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;
}
}