Introduction

System.Web.Mail can be used to send emails from .NET 1.1 applications. Sending simple emails is very easy. It is more complicated when you try to send emails using a SMTP server that requires authentication, or even when you just need to format the From name of the email you want to send.

Background

Here is the most simple piece of code that will send an email using C#:

Even more complicated will be to send an email using a SMTP server that requires authentication. For that, the Fields collection of the MailMessage object needs to be used. Here is the sample piece of code that will help you solve your problems:

There are SMTP servers that require SSL. One very well known example is Gmail. In order to send emails using the Gmail SMTP server, you need to specify that and also set the correct port. The following example can be used to send emails using the Gmail SMTP:

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

Share

About the Author

Comments and Discussions

Hello,
The example works fine while I use the Asp.Net Development Server, but when I deploy the site on IIS the Send() method throw an exception: "The transport failed to connect to the server." Does anyone have a suggestion please!!
Thanks.