Mail

Posted by Tushar under C# on 4/3/2009 | Views : 1452 | Status : [Member] | Replies : 1
Hi All.........
How are U?.....

How to attach a file to the Mail application in C#.
i want to send a file to the sender through the mail in C#.
i want to code to send mail with attachment of file to the sender in C#.

Advance thanks.........
Have nice Day...




Responses

Posted by: Vuyiswamb on: 4/6/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day Tushar

Here is your Answer

Sending a Simple Mail

MailMessage mail = new MailMessage();


mail.To.Add("to@gmail.com");

mail.From = new MailAddress("from@gmail.com");

mail.Subject = "Test Email";

string Body = "Welcome to CodeDigest.Com!!";

mail.Body = Body;

SmtpClient smtp = new SmtpClient();

smtp.Host = ConfigurationManager.AppSettings["SMTP"];

smtp.Send(mail);


http://www.dotnetcurry.com/ShowArticle.aspx?ID=65&AspxAutoDetectCookieSupport=1

or

Sending Mail with Attachment

We can also send email with attachments. The below code will help you to achieve it.



MailMessage mail = new MailMessage();

mail.To.Add("to@gmail.com");

mail.From = new MailAddress("From@gmail.com");

mail.Subject = "Test Email";

string Body = "Welcome to CodeDigest.Com!!";

mail.Body = Body;

mail.Attachments.Add(new Attachment(@"F:\Articles\Email in ASP.Net 2.0\SendEmail\mail.png"));

SmtpClient smtp = new SmtpClient();

smtp.Host = ConfigurationManager.AppSettings["SMTP"];

smtp.Send(mail);


Or here is a nice Article by Haresh Chaudhari

http://www.dotnetspider.com/resources/21405-Send-Email-with-Attachments-Asp-net--with-C-Net.aspx

Thank you for posting in DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Tushar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response