Click here to Skip to main content
11,410,365 members (60,148 online)
Click here to Skip to main content
Alternatives (2)

Tagged as

Sending an Email in C# with or without attachments: generic routine.

, 3 Mar 2011 CPOL
Sending an email is not a real problem, but I am fed up with answering the question "How do I do it?" in Q&A . So, here is the generic routine I use to send an email, with or without attachments, so I can just point people at it!

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

3 Mar 2011
Manas Bhardwaj
I would use Attachment [^] instead of MailAttachment[^]One should also use System.net.mail[^] instead of System.Web.Mail[^] which is now obsolete.
8 Mar 2011
Hariharan Arunachalam
These are the same classes in VB.NET in case needed.I've also made the mail server address a parameter to allow the code to be runnable on copy paste.The problem while sending the bigger files was the smtp client's timeout(default 100s). I've made this dependent on the attachments' size...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

OriginalGriff
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?
Follow on   Google+

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.150414.5 | Last Updated 3 Mar 2011
Article Copyright 2011 by OriginalGriff
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid