How to send email from using c#.net/asp.net code
// ADVANCE EMAIL SENDING WITH ATTACHMENT OPTION
// FOR C#.NET ,ASP.NET
// Below Function can be used for sending a email with attachment option using c# code
// using gmail crdential
public bool mailattachement2(string to, string replyto, string body, string subject, FileUpload f1, FileUpload f2)
{
MailMessage mail = new MailMessage();
mail.To.Add(to);
mail.From = new MailAddress("xyz@gmail.com","Client Enquiry");
mail.Subject = subject;
mail.Body = body;
MailAddress rt = new MailAddress(replyto);
mail.ReplyTo = rt;
//mail.Sender = rt;
mail.IsBodyHtml = true;
if (f1.HasFile)
{
mail.Attachments.Add(new Attachment(f1.PostedFile.InputStream, f1.FileName)); //add the attachment
}
if (f2.HasFile)
{
mail.Attachments.Add(new Attachment(f2.PostedFile.InputStream, f2.FileName)); //add the attachment
}
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "password");
// Set the one email id and its password for authentication )
// email goes via using above email id...
smtp.Port = 587;
smtp.EnableSsl = true;
try
{
smtp.Send(mail);
return (true);
}
catch (Exception ex)
{
return (false);
}
}