..
As we all know now the emails are a very popular communication mechanism, particularly for its ease of use. For a programmer so this is a key tool to enable your applications to send messages, reports and files between users.
Starting with version 2.0. NET Framework has been introduced the System.Net.Mail namespace, which provides several classes that allow you to create and send email messages. These messages can include simple text, HTML and attachments. In practice the transmission of an email can be divided into two steps: creating and sending the same message to an SMTP (Simple Mail Transfer Protocol).
The creation of an email message can be simple or complex. In its simplest version consists of an email message from a sender, a recipient, and the body of an object, ie the actual message. This simple type of email can be created with a single line of code using the. NET Framework. In more complex versions of the email may also have a type of custom coding, contain HTML code, contain pictures (as attachments) or have embedded images in HTML.
To create and send an email message must follow the following steps:
Let us now see how to do this. The MailMessage class provides four constructors that allow you to create an empty message, or, in the most complete version, a message sender, recipient, subject and message body. We see below an example that uses the constructor with the maximum number of parameters
MailMessage msg = new MailMessage ("mittente@mittente.com"
"Destinatario@destinatario.com", "Subject", "Contents of the email");
It 'can also specify the sender and recipient in the form of MailAddress objects. An object of this type allows you to specify an email address, but also to specify the display name instead of the same (aliases) and the type of encryption, such as the following example shows
MailMessage msg = new MailMessage (
new MailAddress ("mittente@mittente.com", "Sender Name Displayed"),
new MailAddress ("destinatario@destinatario.com"
"Recipient Name Displayed"));
To specify the type of encryption you must use another constructor of the MailAddress
MailMessage msg = new MailMessage (new MailAddress ("mittente@mittente.com"
"Sender Name Displayed" Encoding.ASCII)
new MailAddress ("destinatario@destinatario.com"
"Recipient Name Displayed" Encoding.ASCII));
however, rarely need to specify the encoding type.
| |
OpenOffice (Ebook)
The open-source software for managing the office work. Just 25 €. |
| |
Web Marketing (Course)
Site promotion, search engines and marketing. From 39 €. |
| |
Webmaster Base (First)
Create a Web site from scratch. Starting from 29 €. |