The namespace
System.Net.Mail used to send email if you are using the 2.0 (or higher) .NET Framework.
Unlike System.Web.Mail, which was introduced in the 1.0 Framework, it is not built upon the CDO/CDOSYS libraries. Instead it is written from the ground up without any interop. Thus, it is not dependant upon other COM libraries.
What happens when we call the System.Net.Mail
First, and foremost, weneed the .NET Framework installed. Then you need to use the System.Net.Mail namespace to create and send email messages. Once you have programmatically set up your application, you will need a relay server to send email through. A relay server is a mail server, or a SMTP server/service, that can handle sending email. System.Net.Mail simply sends the mail to a relay server, and the relay server is responsible for delivering it to the final destination. System.Net.Mail can only send email. To read email you either need a Mime parsing component such as aspNetMime or a POP3 component such as aspNetPOP3.
Example code with GMail SMTP
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("yourid@gmail.com", "yourpwd");
mail.To.Add(Rajesh@gmail.com);
mail.Subject = "subject";
mail.From = new System.Net.Mail.MailAddress(pillai.in@gmail.com);
mail.IsBodyHtml = true;mail.Body = "message";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
smtp.Send(mail);
No comments:
Post a Comment