This code sample lets you send email using Gmail account. The steps involved are explained.
public static void SendMail(string Host, int Port, string strUserName, string strPassword, string strFromName, string strFromEmail, string strToName, string strToEmail, string strHeader, string strMessage, bool bAuthenticated) { if (strToName.Length == 0) strToName = strToEmail; if (strFromName.Length == 0) strFromName = strFromEmail; System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage(); Mail. //System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage(); Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = Host; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = Port.ToString(); if (bAuthenticated) { Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true"; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = strUserName; Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = strPassword; } Mail.To = strToEmail; Mail.From = strFromEmail; Mail.Subject = strHeader; Mail.Body = strMessage; Mail.BodyFormat = System.Web.Mail.MailFormat.Html;
System.Web.Mail.SmtpMail.SmtpServer = Host; System.Web.Mail.SmtpMail.Send(Mail); }
And call the Function as
SendMail("smtp.gmail.com", 465, "danasegarane@gmail.com", "YourGmail Password", "Dana", "danasegarane@gmail.com", "Danasegarane", "danasegarane@gmail.com", "Hi Dana ", "Hello How are u !", true);
|
| Author: Pradeep Y 03 Nov 2008 | Member Level: Gold Points : 0 |
Hi,
Thanks for that !!
Regards Pradeep
|