Introduction:
In this article demonstrates,how to send a email with attachment using asp.net.
Main:
In asp.net2.0 we have a very straight forward option(mail.attachments.add()), is available for adding ‘n’ number of attachemts.Please check the below sample code,
Sample Code:
MailMessage NetProgrammingHelp_Mail = new MailMessage();
NetProgrammingHelp_Mail.To.Add("netprogramminghelp@gmail.com");
NetProgrammingHelp_Mail.From = new MailAddress("sample@gmail.com");
NetProgrammingHelp_Mail.Subject = "Hi,This is my mail with attachment";
NetProgrammingHelp_Mail.Body = "Enjoy this Code";
NetProgrammingHelp_Mail.IsBodyHtml = true;
NetProgrammingHelp_Mail.Attachments.Add(new Attachment(@"C:\sample.txt", sample.txt));
SmtpClient smtp = new SmtpClient();
smtp.Host = "SmtpNetProgrammingHelp.com";
smtp.Credentials = new System.Net.NetworkCredential
("NetProgrammingHelp_MailID@gNetProgrammingHelp_Mail.com", "NetProgrammingHelp_MailPassword"); //Use yours own userid and password,for ex,gmail userid and password.
smtp.EnableSsl = true;
smtp.Send(NetProgrammingHelp_Mail);
MailMessage NetProgrammingHelp_Mail = new MailMessage(); NetProgrammingHelp_Mail.To.Add("netprogramminghelp@gmail.com"); NetProgrammingHelp_Mail.From = new MailAddress("sample@gmail.com"); NetProgrammingHelp_Mail.Subject = "Hi,This is my mail with attachment"; NetProgrammingHelp_Mail.Body = "Enjoy this Code"; NetProgrammingHelp_Mail.IsBodyHtml = true; NetProgrammingHelp_Mail.Attachments.Add(new Attachment(@"C:\sample.txt", sample.txt)); SmtpClient smtp = new SmtpClient(); smtp.Host = "SmtpNetProgrammingHelp.com"; smtp.Credentials = new System.Net.NetworkCredential ("NetProgrammingHelp_MailID@gNetProgrammingHelp_Mail.com", "NetProgrammingHelp_MailPassword"); //Use yours own userid and password,for ex,gmail userid and password. smtp.EnableSsl = true; smtp.Send(NetProgrammingHelp_Mail); |
Conclusion:
Hope,this helps
Happy Coding.
No matter what others say, I think it is still interesting and useful maybe necessary to improve some minor things
I love your website! did you create this yourself or did you outsource it? Im looking for a blog design thats similar so thats the only reason I’m asking. Either way keep up the nice work I was impressed with your content really..
I love your website! did you create this yourself or did you outsource it? Im looking for a blog design thats similar so thats the only reason I’m asking. Either way keep up the nice work I was impressed with your content really..
KOVAL ! why do you only respond to people who threaten to unsubscribe… what about me….Id like a shout out too ….I watched all your videos….TWICE…..i loved you when you weren’t? famous…. *sigh*