|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis article is to show the reader how easy it is to send an email using the .NET framework. Not only can the user determine the format of the email (HTML or text), non-ASCII characters can also be sent with relatively simple coding. A Windows email client application along with the source code can be found in this article. Configuring a PC to use the applicationSome configuration needs to be done before you can make use of the application.
Using the codeIn order to make use of the mail services from .NET, you need to have a reference to First, you need to create a MailMessage mm = new MailMessage();
Next, you need to set the members of the //Setting the fields of the emails
mm.To = toText.Text;
mm.From = fromText.Text;
mm.Cc = ccText.Text;
mm.Bcc = bccText.Text;
mm.Subject = subjectText.Text;
//The body of the message text
mm.Body = messageText.Text;
//The Priority of the mail
switch (settingDialog.PrEnum)
{
case Priorities.High:
mm.Priority = MailPriority.High;
break;
case Priorities.Normal:
mm.Priority = MailPriority.Normal;
break;
case Priorities.Low:
mm.Priority = MailPriority.Low;
break;
default:
break;
}
//The encoding format of the mail
switch (settingDialog.EdEnum)
{
case Encodings.ASCII:
mm.BodyEncoding =Encoding.ASCII;
break;
case Encodings.Unicode:
mm.BodyEncoding =Encoding.Unicode;
break;
case Encodings.UTF7:
mm.BodyEncoding =Encoding.UTF7;
break;
case Encodings.UTF8:
mm.BodyEncoding =Encoding.UTF8;
break;
default:
break;
}
//Format of mail is in HTML format
mm.BodyFormat = MailFormat.Html;
if (!attachText.Text.Equals(""))
{
//adding attachments.
//You can add multiple attachments if you want
MailAttachment ma = new MailAttachment(attachText.Text);
if (ma != null)
{
mm.Attachments.Add(ma);
}
}
To send the mail, make use of the SmtpMail.Send(mm);
As you can see, to send a mail with .NET is really that simple. Known Issues
Troubleshooting
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||