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 Iyer 03 Nov 2008 | Member Level: Diamond Points : 0 |
Hi,
Thanks for that !!
Regards Pradeep
|
| Author: D.Jeya kumar(JK) 15 May 2009 | Member Level: Diamond Points : 1 |
Hi,
This SMTP server is not working... Please test it once before posting...
Regards JK
|
| Author: Danasegarane.A 15 May 2009 | Member Level: Diamond Points : 1 |
I tested it previously... It was working..
Let me check it once again
Dana
|
| Author: Muralidharan Rangaraju 17 May 2009 | Member Level: Gold Points : 1 |
Hi Danasegarane,
For gmail SMTP server we can also use port number 587 instead of 465. In some networks 465 works and in some network 587 will work. For JK this may be a problem.
Regards, Murali
|
| Author: Sasikumar 19 May 2009 | Member Level: Gold Points : 1 |
Hai Danasegarane.A,
This SMTP server is not working, Please Check and test before posting the Resource
Regards Sasikumar
|
| Author: Danasegarane.A 19 May 2009 | Member Level: Diamond Points : 1 |
Hi Sasikumar, I have never posted resource without properly checking. It was working well for me...
Check the Murli's comment
|