Wednesday 1 February 2012

In asp.net Sending Attachments Directly From a FileUpload

if(FileUpload1.HasFile)
{
    string toAddress = "to_mailid";
    stringfromAddress = "your_mailid";
    string mailServer = "smtp.smtpservername.com";
    MailMessagemyMailMessage = new MailMessage();
    myMailMessage.To.Add(toAddress);
    myMailMessage.From = new MailAddress(fromAddress);
    myMailMessage.Subject = "Test Message";
    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
    AttachmentmyAttachment = new Attachment(FileUpload1.FileContent,fileName);
    myMailMessage.Attachments.Add(myAttachment);
    SmtpClientmySmtpClient = new SmtpClient(mailServer);
    mySmtpClient.Send(myMailMessage);
}

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger