Frequently Asked Questions for System.Net.Mail
By Dave Wanta
This FAQ addresses the System.Net.Mail (SNM) namespace found in the 2.0 .NET Framework.
It starts with an Introduction and Programming Samples.
If you need to support the 1.x .NET Framework, be sure to check out my System.Web.Mail website here.
1 Introduction
1.1 What is System.Net.Mail?
1.2 What is the .NET Framework ?
1.3 What do I need to send email in .NET?
1.4 What is a relay server?
1.5 What is the IIS SMTP Service?
1.6 Can System.Net.Mail read email?
2 Exploring System.Net.Mail Classes
2.1 MailMessage Class
2.2 MailAddress Class
2.3 Attachment Class
2.4 SmtpClient Class
2.5 AlternateView Class
2.6 Linked Resource
3 Quickstart Programming Samples
3.1 Working with the Body
3.1.1 How do I send a plain text email?
3.1.2 How do I send a simple Html email?
3.1.3 How do I create a Multi-Part mime message?
3.2 Working with Addresses
3.2.1 How do I change the FROM address to a friendly name?
3.2.2 How do I change the TO address to a friendly name?
3.2.3 How do I specify multiple recipients?
3.2.4 How do I create a friendly non-ascii display name?
3.3 Working with Headers
3.3.1 How do I change the email priority?
3.3.2 How do I add the Reply-To header to the MailMessage?
3.3.3 How do I request a read receipt?
3.3.4 How do I add custom headers to the MailMessage?
3.4 Working with Attachments
3.4.1 How do I send an email with attachments?
3.4.2 How do I create an attachment from a stream?
3.5 Accessing Config File Mail Settings Programmatically
4 Advanced Programming Samples
4.1 How do I read SMTP configuration data?
4.10 How do I create a log file of the SMTP session?
4.11 How do I encrypt messages using s/mime or pgp?
4.2 How do I authenticate to send an email?
4.3 How do I change the SMTP port number?
4.4 How do I embed images in an email?
4.5 How do I send an email over SSL?
4.6 How do I send email asynchronously?
4.7 How do I write to the Pickup directory?
4.8 How do I send a web page?
4.9 How do I send non US-ASCII emails?
5 Troubleshooting System.Net.Mail
5.1 Bccs are not so blind.
5.2 Cannot enable SSL with a username and password.
6 Additional Help
More...
http://www.systemnetmail.com/
Showing posts with label Email. Show all posts
Showing posts with label Email. Show all posts
Monday, September 8, 2008
Sending Email with System.Net.Mail
Scott Gu
NET 2.0 includes much richer Email API support within the System.Net.Mail code namespace. I've seen a few questions from folks wondering about how to get started with it. Here is a simple snippet of how to send an email message from “sender@foo.bar.com” to multiple email recipients (note that the To a CC properties are collections and so can handle multiple address targets):
MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");
message.To.Add(new MailAddress("recipient1@foo.bar.com"));
message.To.Add(new MailAddress("recipient2@foo.bar.com"));
message.To.Add(new MailAddress("recipient3@foo.bar.com"));
message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
System.Net.Mail reads SMTP configuration data out of the standard .NET configuration system (so for ASP.NET applications you’d configure this in your application’s web.config file). Here is an example of how to configure it:
More...
http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx
NET 2.0 includes much richer Email API support within the System.Net.Mail code namespace. I've seen a few questions from folks wondering about how to get started with it. Here is a simple snippet of how to send an email message from “sender@foo.bar.com” to multiple email recipients (note that the To a CC properties are collections and so can handle multiple address targets):
MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");
message.To.Add(new MailAddress("recipient1@foo.bar.com"));
message.To.Add(new MailAddress("recipient2@foo.bar.com"));
message.To.Add(new MailAddress("recipient3@foo.bar.com"));
message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
System.Net.Mail reads SMTP configuration data out of the standard .NET configuration system (so for ASP.NET applications you’d configure this in your application’s web.config file). Here is an example of how to configure it:
More...
http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx
Handy ASP.NET Email Control
By Trevor Swanepoel
An email feedback control written in VB.NET
Introduction
Most websites have the need for some sort of "feedback form" or "email-us" page, which, as we know, is tedious to re-develop on every site, even in .NET. I have developed this simple E-Mail control in VB.NET that can be wrapped around any form to be turned into an email form, even with file inputs.
The first major thing to overcome is the property which must be set just above the CLASS in the .ascx.vb file (no extra linebreaks). This allows the User Control to access the controls on the .aspx page where it is used.
_ 'No extra linebreak after this!!
Public MustInherit Class MailAnything
Inherits System.Web.UI.UserControl
If you do have a file input on your web form remember to set the enctype="multipart/form-data".
Another important thing to remember is to use Web Forms Labels to name your fields on the web form so that it can be read by your user control and form part of the email.
The basic elements of the form in the .aspx file is as follows (example).
http://www.codeproject.com/KB/vb/tsmailcontrol.aspx
Also don't forget to register your User control in the .aspx file
<%@ Register TagPrefix="Bluegrass" TagName="Mailer" Src="controls/MailAnything.ascx" %>
The rest is then all done in the user control which can be re-used in any project. Here is how I did the user control:
More...
http://www.codeproject.com/KB/vb/tsmailcontrol.aspx
An email feedback control written in VB.NET
Introduction
Most websites have the need for some sort of "feedback form" or "email-us" page, which, as we know, is tedious to re-develop on every site, even in .NET. I have developed this simple E-Mail control in VB.NET that can be wrapped around any form to be turned into an email form, even with file inputs.
The first major thing to overcome is the
Public MustInherit Class MailAnything
Inherits System.Web.UI.UserControl
If you do have a file input on your web form remember to set the enctype="multipart/form-data".
Another important thing to remember is to use Web Forms Labels to name your fields on the web form so that it can be read by your user control and form part of the email.
The basic elements of the form in the .aspx file is as follows (example).
http://www.codeproject.com/KB/vb/tsmailcontrol.aspx
Also don't forget to register your User control in the .aspx file
<%@ Register TagPrefix="Bluegrass" TagName="Mailer" Src="controls/MailAnything.ascx" %>
The rest is then all done in the user control which can be re-used in any project. Here is how I did the user control:
More...
http://www.codeproject.com/KB/vb/tsmailcontrol.aspx
Send mail through .aspx C#
By benjarras
How to send an email in Dot Net
All the Contact Us forms needs an e-mail system
In this article you will learn how to send emails from you .aspx site, using plain format, html format also add attachments by two ways, the quick (easy way) and the profesional ( i like this way ) The first step is be sure that the SMTP Server is locally installed at SMTP Service of the IIS
Easy Way
This is an easy and quick way to do that, we will call this form ContactMe.aspx First, we have to import the System.Web.Mail Then in the code behind add the namespace
using System.Web.Mail;
Now build your message
string To = "cgodinez@technomex.net";
string From = "mymail@mail.com";
string Subject = "The Famous";
string Body = "Hello World";
SmtpMail.Send(From,To,Subject,Body);
What is the SmtpMail?
this class has a method called Send that allows the user to send an email, in this way we set four parameters:
SmtpMail.Send("mymail@mail.com","cgodinez@technomex.net","The Famous","Hello World");
As you can see this is the easy and quick way to do that. Now you will lear how to do the professional way (interesting). Here you will send an email including an attachment and CC, we can use the same parameters above
Professional Way (I like this Way)
We have to create an object (MailMessage) called myMail
More...
http://www.codeproject.com/KB/aspnet/mailing.aspx
How to send an email in Dot Net
All the Contact Us forms needs an e-mail system
In this article you will learn how to send emails from you .aspx site, using plain format, html format also add attachments by two ways, the quick (easy way) and the profesional ( i like this way ) The first step is be sure that the SMTP Server is locally installed at SMTP Service of the IIS
Easy Way
This is an easy and quick way to do that, we will call this form ContactMe.aspx First, we have to import the System.Web.Mail Then in the code behind add the namespace
using System.Web.Mail;
Now build your message
string To = "cgodinez@technomex.net";
string From = "mymail@mail.com";
string Subject = "The Famous";
string Body = "Hello World";
SmtpMail.Send(From,To,Subject,Body);
What is the SmtpMail?
this class has a method called Send that allows the user to send an email, in this way we set four parameters:
SmtpMail.Send("mymail@mail.com","cgodinez@technomex.net","The Famous","Hello World");
As you can see this is the easy and quick way to do that. Now you will lear how to do the professional way (interesting). Here you will send an email including an attachment and CC, we can use the same parameters above
Professional Way (I like this Way)
We have to create an object (MailMessage) called myMail
More...
http://www.codeproject.com/KB/aspnet/mailing.aspx
Subscribe to:
Posts (Atom)