Email consists:
-From
-To
-CC
-BCC
-Subect
-Body
depend on these fields, below is the ASP.NET code to send the message:
First, add this namespace 'using System.Web.Mail' to your aspx.cs page.
then inside the button_click event, add this code:
MailMessage mail = new MailMessage();
mail.From = "someone@google.com";
mail.To = "somebody@google.com";
mail.Cc = "badgirl@google.com";
mail.Subject = "Just to say hi";
mail.Bcc = "badboy@google.com";
mail.Body = "Happy B'day to you!!";
//If you are using different mail server, please replace this one by your own...
SmtpMail.SmtpServer = "smtp.gmail.com";
SmtpMail.Send(mail);
Sending Attachments:
mail.From = "someone@google.com";
mail.To = "somebody@google.com";
mail.Cc = "badgirl@google.com";
mail.Subject = "Just to say hi";
mail.Bcc = "badboy@google.com";
mail.Body = "Happy B'day to you!!";
mail.BodyFormat = MailFormat.Text;
mail.Attachments.Add(new MailAttachment("c:\\temp\\test.pdf"));
SmtpMail.SmtpServer = "smtp.gmail.com";
SmtpMail.Send(mail);
Happy Coding!!!
No comments:
Post a Comment
Highly Appreciated your comments