22 September 2008

Send Email using ASP.NET

In ASP.NET (using C#), it is very easy to send email. You need to include the namespace 'System.Web.Mail'. The rest is as follows-

MailMessage mailMsg = new MailMessage();
mailMsg.To = "ToSomeone@mail.com";
mailMsg.From = "FromSomeone@mail.com";
mailMsg.Subject = "subject of mail";
mailMsg.Body = "body of mail";

SmtpMail.Send(mailMsg);

Attachment:
Sending attachment is also simple.

MailAttachment attachment = new MailAttachment("FilePath");
mailMsg.Attachments.Add(attachment);


Note: The FilePath is the path in Server, not in client. So if you want to send attachment, first save the file in server temporarily, send mail and then delete the temporary file.

 

© 2007 t!ps n tr!cks: Send Email using ASP.NET



Template unik dari rohman


---[[ Skip to top ]]---