Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
send a mail with attachemt source code in asp.net
Posted

 
Share this answer
 
Quote:

Hi..

MailMessage message = new MailMessage();
message.From = new MailAddress("xyz@gmail.com");
message.To.Add(anothermail);
message.Subject = "your subject";
message.Body = "your message body";
message.IsBodyHtml = true;
if (IsAttachmentValid(FileUploadAttachment))
{
message.Attachments.Add(new Attachment(FileUploadAttachment.PostedFile.InputStream, FileUploadAttachment.FileName));
}

SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "");
smtpClient.EnableSsl = true;
smtpClient.Send(message);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900