Send Email in C#.NET

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!
 
P

PvdG42

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top