.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Sending HTML Emails with an attachements

Posted By:Ashutosh Jha       Posted Date: February 27, 2014    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

Continouing to my previous aricle - sending Plan and HTML Emails in Asp.net. Here i will explain how we can attach files while sending emails.
 

Lets create a page mailattach.aspx
With certain email components, sending attachments can be a bit of an interesting feature . With .Net, it is just another easy to use component: MailAttachment. The following code demonstrates how an attachment can be added to the MailMessage (mailattach.aspx). Now see the below code to send an email witha n attachements.

<% @Page Language="C#" %>
<% @Import Namespace="System.Web.Mail" %>
<%
MailMessage msgMail = new MailMessage();

msgMail.To = "ashutosh@gmail.Com";
msgMail.From = "ashutosh@gmail.Com";
msgMail.Subject = "Email With an attachement";

msgMail.BodyFormat = MailFormat.Text;
msgMail.Body = "Please find the attachment!";
msgMail.Attachments.Add(new MailAttachment("c:\\files\\demo.pdf"));

SmtpMail.Send(msgMail);

Response.Write("Email with an attachement sent successfully");
%>

The line in the above code-

msgMail.Attachments.Add(new MailAttachment("c:\\files\\demo.pdf"));

Shows a path to the program from where it need to take the files. Here it will take from files folder from the C drive of your system.

Happy Learning !

 

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend