Send Email in C#.NET

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

Hi,

I wish to be able to send an email in my C#.NET code in the following
format:

MailMessage objEmail = new MailMessage();
objEmail.To = "(e-mail address removed)";
objEmail.From = "(e-mail address removed)";
objEmail.Subject = "Test Email";
objEmail.Body = "Price Mover test";
objEmail.Priority = MailPriority.High;
//SmtpMail.SmtpServer = "localhost";
try{
SmtpMail.Send(objEmail);
Response.Write("Your Email has been sent sucessfully -
Thank You");
}
catch (Exception exc){
Response.Write("Send failure: " + exc.ToString());
}

However, I know that I must use a namespace related to email. What is
that namespace?
Also neither "SmtpMail" nor "MailMessage" is recognized by the
compiler. Any advice on how to make this work?

Thanks!
 
Curious said:
Hi,

I wish to be able to send an email in my C#.NET code in the following
format:

MailMessage objEmail = new MailMessage();
objEmail.To = "(e-mail address removed)";
objEmail.From = "(e-mail address removed)";
objEmail.Subject = "Test Email";
objEmail.Body = "Price Mover test";
objEmail.Priority = MailPriority.High;
//SmtpMail.SmtpServer = "localhost";
try{
SmtpMail.Send(objEmail);
Response.Write("Your Email has been sent sucessfully -
Thank You");
}
catch (Exception exc){
Response.Write("Send failure: " + exc.ToString());
}

However, I know that I must use a namespace related to email. What is
that namespace?
Also neither "SmtpMail" nor "MailMessage" is recognized by the
compiler. Any advice on how to make this work?

Thanks!

Here are some places in MSDN to start looking:

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx

http://msdn.microsoft.com/en-us/library/ms173026.aspx
 
Back
Top