Send email with attachment - .net

I have seen many posts over forums asking for how to send emails in asp.net.

In this blog post, I am going to post code snippet to send email in asp.net (with attachment).

Check out Below Code to send email with attachment in asp.net:

public static bool SendMail(string strFrom, string strTo, string strSubject, string strMsg)
{
try
{
// Create the mail message
MailMessage objMailMsg = new MailMessage(strFrom, strTo);

objMailMsg.BodyEncoding = Encoding.UTF8;
objMailMsg.Subject = strSubject;
objMailMsg.Body = strMsg;
Attachment at = new Attachment(Server.MapPath("~/Uploaded/txt.doc"));
objMailMsg.Attachments.Add(at);
objMailMsg.Priority = MailPriority.High;
objMailMsg.IsBodyHtml = true;

//prepare to send mail via SMTP transport
SmtpClient objSMTPClient = new SmtpClient();
objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
objSMTPClient.Send(objMailMsg);
return true;
}
catch (Exception ex)
{
throw ex;
}
}

Contact Form

Name

Email *

Message *

Popular Posts

List of Things to Pack for U.S.

Calling COM From T-SQL

20 Top Best Places/Cities To Live In United States Of America For The Year 2011

Life Cycle of a Web Request

Python Keywords

Internal Revenue Service (IRS) - Questions About Your Tax Refunds In US