Code for Sending E-Mail with System.Web.Mail?

Answers were Sorted based on User's Feedback



Code for Sending E-Mail with System.Web.Mail?..

Answer / vamshi

using System;
using System.Web.Mail;

namespace vamshi.SendMail
{
/// <summary>
/// Test console application to demonstrate sending e-
mail.
/// </summary>
class TestMail
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
TestMail.Send("testuser@yahoo.com",
"mstrawmyer@crowechizek.com",
"Test Message Using CDOSYS",
"Hello World! This is a simple message
sent
using CDOSYS.");
}

/// <summary>
/// Send a message using the .NET wrapper for
Collaborative Data
/// Objects (CDO). This method should be used when
sending to a
/// single recipient only; otherwise, the list of
recipients
/// will be known.
/// </summary>
/// <param name="MessageFrom">Message originator</param>
/// <param name="MessageTo">Message receipent</param>
/// <param name="MessageSubject">Message subject</param>
/// <param name="MessageBody">Message body</param>
public static void Send(string MessageFrom,
string MessageTo,
string MessageSubject,
string MessageBody)
{
MailMessage message = new MailMessage();
message.From = MessageFrom;
message.To = MessageTo;
message.Subject = MessageSubject;
message.BodyFormat = MailFormat.Text;
message.Body = MessageBody;

try
{
System.Console.WriteLine("Sending outgoing
message");
SmtpMail.Send(message);
}
catch( System.Web.HttpException exHttp )
{
System.Console.WriteLine("Exception occurred:" +
exHttp.Message);
}
}
}
}

Is This Answer Correct ?    0 Yes 0 No

Code for Sending E-Mail with System.Web.Mail?..

Answer / ramesh

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;

public partial class email : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
NetworkCredential mylogin = new
NetworkCredential("yraddress@gmail.com","yourpassword");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("yraddress@gmail.com@gmail.com");
msg.To.Add(new MailAddress(TextBox1.Text));
// in Textbox1 you will put receiver gmail address,as this
example work with gmail only.
msg.Subject = TextBox2.Text;
// subject pass through textbox2
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = TextBox3.Text;
//msgbody pass through textbox3
msg.Priority = MailPriority.High;
msg.IsBodyHtml = true;

SmtpClient client = new
SmtpClient("smtp.gmail.com");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = mylogin;
client.Send(msg);


}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More ASP.NET Code Interview Questions

hold checkbox values

4 Answers  


what is software testing

1 Answers   TCS,


How we implement the paypal in my website and how we make a payment through Credit Card.

2 Answers  


Common UI for Multiple web applications. Suppose there are 35 websites using same third party controls.These 3rd party controls are made together that all 35 websites can use these controls.If we put all 3rd party controls and use its dll in 35 websites,only class files will be accessable. But I want to use CSS,images also in all 35 websites. how I can design the N-tier solution for this project.

0 Answers   TCS,


Code for Using Keyboard Events?

0 Answers  






Coding for Synchronizing Cache Access in ASP.NET?

0 Answers  


How to get the row index on checking a Checkbox in a ListView

1 Answers   TCS,


Code for Presenting Parent/Child Data in a Data Grid Row?

0 Answers   TCS,


Coding for .NET Delegates?

0 Answers  


How to add checkbox to datagrid?

5 Answers  


i have a gird with columns all are coming from database,this will bind in item templete in gridview as textboxex.and i have button below named Update.i want to update all the records in the grid,but if user change the value of one textbox,what is the easy way 2 do this

0 Answers   Crompton Greaves,


how to upload an excel in c# ASP.Net?

3 Answers  


Categories
  • ASP.NET Code Interview Questions ASP.NET Code (46)
  • VB.NET Code Interview Questions VB.NET Code (9)
  • C Sharp Code Interview Questions C Sharp Code (51)
  • ADO.NET Code Interview Questions ADO.NET Code (8)