C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Email »

Sending email using Gmail SMTP


Posted Date: 11 Apr 2008    Resource Type: Code Snippets    Category: Email
Author: senthilMember Level: Silver    
Rating: 1 out of 5Points: 7



This code uses gmail smtp to send emails. It uses authentication. Replace username with your gmail username and password with gmail password



using System.Net;
using System.Net.Mail;
using System.Text;

namespace aspspiderfreebooks.Net
{
public class WebMail
{
public static void SMTP()
{
MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("youremail@example.com");
mailMsg.To.Add("someone@example.com");
mailMsg.Subject = "Test subject";
mailMsg.IsBodyHtml = true;
mailMsg.BodyEncoding = Encoding.UTF8;
mailMsg.Body = "This email is sent from asp.net code";
mailMsg.Priority = MailPriority.Normal;
// Smtp configuration
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("youremail@gmail.com", "yourpassword");
client.Port = 587; //or use 465
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
object userState = mailMsg;
try
{
//you can also call client.Send(msg)
client.SendAsync(mailMsg, userState);
}
catch (SmtpException)
{
//Catch errors...
}
}
}
}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

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: Send Emails with Gmail Account with Attachment
Previous Resource: Mail using ASP.NET , c#
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use