C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Send Email using Gmail


Posted Date: 20 Jun 2008    Resource Type: Code Snippets    Category: Email

Posted By: Danasegarane.A       Member Level: Diamond
Rating:     Points: 4



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);







Responses

Author: Pradeep Y    03 Nov 2008Member Level: Gold   Points : 0
Hi,

Thanks for that !!

Regards
Pradeep


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sending E-Mail using .NET  .  Sending E-Mail from C#  .  Send E-Mail from ASP.NET web page  .  Send E-Mail from .net applications  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to send E-mail from .NET applications
Previous Resource: Sending E-Mail through SQL Server stored procedures
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use