| C# can send emails with the .NET Framework fairly | | | | and password. This will authenticate your connection |
| easily, especially via the SMTP protocol. The SMTP | | | | with the server. Just make sure your username |
| protocol is a common way to send emails. | | | | includes |
| Because SMTP emails require an SMTP server to | | | | Everything is handled through SmtpClient class. The |
| send, it is probably easiest to use Google's Gmail | | | | class encapsulates some pretty powerful functions, |
| server. Thus you'll need a Gmail account, which is | | | | including adding attachments and sending HTML |
| simple and free to create. Once you have a Gmail | | | | emails. HTML emails are emails that are written with |
| account sending SMTP emails with C# is a breeze. | | | | HTML code and are displayed while web pages. |
| The trick is to use the System.Net.Mail namespace | | | | Although it depends on the email client, most clients |
| instead of System.Web.Mail. The second namespace | | | | can read HTML emails without a problem, allowing |
| was replaced by System.Net starting on .NET | | | | your C# application to send emails with images and |
| Framework 2.0. | | | | formatted text. The SmtpClient class also allows |
| But what do you do to connect to Google's server? | | | | developers to add headers, which can fine-tune the |
| You need a few bits of information. The first is that | | | | behavior of emails. However be aware that some |
| Gmail's SMTP server address is The second thing you | | | | SMTP servers, like Google's, will ignore certain |
| need to know is that the C# application must | | | | headers and just use information from your account. |
| connect through port 587. How do we know this? | | | | For example, setting the From field to something else |
| The information is provided to developers freely by | | | | will be ignored by GMail, which will automatically set |
| Google. Other SMTP servers also provide their own | | | | the From field to your email address. |
| address and port to connect with. | | | | Lastly make sure SSL is enabled on the C# |
| However there is still one more thing, most SMTP | | | | application. SSL is an encryption protocol and it is |
| servers need authentication to send your emails. This | | | | absolutely required or Gmail's server will not accept |
| is where the Gmail account comes into play. Using the | | | | your connection. |
| NetworkCredential .NET class, specify your username | | | | |