Sending mail in asp.net

Posted on May 12, 2008. Filed under: C# |

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From=new MailAddress(”mymail@gmail.com”);
mail.To.Add(new MailAddress(”sendmail@yahoo.com”));//enter company name which send
mail.IsBodyHtml=true;
mail.Subject = “Sending Enquiry”;
mail.Body = “Enquiry About Company “;
//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential(”maymail@gmail.com”, “password”);
//Smtp Mail server of Gmail is “smpt.gmail.com” and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(”smtp.gmail.com”,587);
//Enable SSL
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(mail);
Response.Flush();
Response.Write(”message was sent successfully!!!”);

 

Make a Comment

Make A Comment: ( 1 so far )

blockquote and a tags work here.

One Response to “Sending mail in asp.net”

RSS Feed for Dream Asp.net Comments RSS Feed

Hi
Can you give us the code for asp.net 1.1 how to
authenticate email details.

Ravikumar
June 2, 2008

Where's The Comment Form?

    About

    Hi,I am Suresh Sharma(MCP) from Gorakhpur , UP, India.I have work on .net technology from 2 years. Key skills-Asp.net 2.0,3.5, Sql 2005,2000. Ajax.net 1.1,C#.net

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS
    • Subscribe in Rojo

    Meta

Liked it here?
Why not try sites on the blogroll...