MailMessage m = new MailMessage();
SmtpClient sc = new SmtpClient();
try
{
m.From = new MailAddress("from@gmail.com", "Shekhar");
m.To.Add(new MailAddress("snawale@curologic.com", "Amit"));
// m.CC.Add(new MailAddress("CC@yahoo.com", "Display name CC"));
//similarly BCC
m.Subject = " This is a Test Mail";
m.IsBodyHtml = true;
m.Body = "Phone number - 9822647640";
/* // Send With Attachements.
FileStream fs = new FileStream("E:\\TestFolder\\test.pdf",
FileMode.Open, FileAccess.Read);
Attachment a = new Attachment(fs, "test.pdf",
MediaTypeNames.Application.Octet);
m.Attachments.Add(a);
*/
/* // Send html email wiht images in it.
string str = "<html><body><h1>Picture</h1><br/><img
src=\"cid:image1\"></body></html>";
AlternateView av =
AlternateView.CreateAlternateViewFromString(str,
null,MediaTypeNames.Text.Html);
LinkedResource lr = new LinkedResource("E:\\Photos\\hello.jpg",
MediaTypeNames.Image.Jpeg);
lr.ContentId = "image1";
av.LinkedResources.Add(lr);
m.AlternateViews.Add(av);
*/
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.Credentials = new
System.Net.NetworkCredential("from@gmail.com", "password");
sc.EnableSsl = true;
sc.Send(m);
Response.Write("Email Send sucessfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
SmtpClient sc = new SmtpClient();
try
{
m.From = new MailAddress("from@gmail.com", "Shekhar");
m.To.Add(new MailAddress("snawale@curologic.com", "Amit"));
// m.CC.Add(new MailAddress("CC@yahoo.com", "Display name CC"));
//similarly BCC
m.Subject = " This is a Test Mail";
m.IsBodyHtml = true;
m.Body = "Phone number - 9822647640";
/* // Send With Attachements.
FileStream fs = new FileStream("E:\\TestFolder\\test.pdf",
FileMode.Open, FileAccess.Read);
Attachment a = new Attachment(fs, "test.pdf",
MediaTypeNames.Application.Octet);
m.Attachments.Add(a);
*/
/* // Send html email wiht images in it.
string str = "<html><body><h1>Picture</h1><br/><img
src=\"cid:image1\"></body></html>";
AlternateView av =
AlternateView.CreateAlternateViewFromString(str,
null,MediaTypeNames.Text.Html);
LinkedResource lr = new LinkedResource("E:\\Photos\\hello.jpg",
MediaTypeNames.Image.Jpeg);
lr.ContentId = "image1";
av.LinkedResources.Add(lr);
m.AlternateViews.Add(av);
*/
sc.Host = "smtp.gmail.com";
sc.Port = 587;
sc.Credentials = new
System.Net.NetworkCredential("from@gmail.com", "password");
sc.EnableSsl = true;
sc.Send(m);
Response.Write("Email Send sucessfully");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
No comments:
Post a Comment