protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
mail.To.Add("imran3may@gmail.com");
mail.To.Add("shi01715@yahoo.com");
mail.From = new MailAddress("shishir64092@gmail.com");
mail.Subject = "Send Email by asp.net code using google or gmail smtp server";
string Body = "Hi, I am testing Email function in asp.net" +
" using google or gmail smtp server"+
" and next time I will send you a document from my .aspx file";
mail.Body = Body;
Attachment at = new Attachment("D:\\Text.txt");
mail.Attachments.Add(at);
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("localhost",25);
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential
("shishir64092@gmail.com", "abcdef");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Send(mail);
Label1.Text = "Mail Send...";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
in
mail.To.Add
you set the mail target address, and in
Credentials
you set the mail sender address with password!