ASP.NET Email Attachment
The System.Net classes uses to communicate with other applications by using the HTTP, TCP, UDP, Socket etc. In the previous chapter we saw how to SMTP email from ASP.NET describes how to send an email with text body . Here in this chapter we are trying to send and email with attachment file.
System.Net.Mail.Attachment class is used with the MailMessage class for sending an email with attachment. Attachment content can be a String, Stream, or file name. You can specify the content in an attachment by using any of the Attachment constructors.
The following ASP.NET program shows how to send an email with an attachment from a Gmail address . The Gmail SMTP server name is smtp.gmail.com and the port using send mail is 587 . Here we are using NetworkCredential for password based authentication.
The above code you have to replace username and password with you gmail user name and password. Also you have to provide the from address as your gmail address.
There is file upload control using in this program for uploading the file from your system to web server.
Click the following links to see full source code