Problems in sending emails in ASP. NET 2.0

Source: Internet
Author: User
Tags mailmessage smtpclient

Prepared by Zhu Xianzhong

In the newly released ASP. NET 2.0 version, Microsoft no longer recommends using the system. Web. Mail namespace instead of the new system. net. Mail namespace. Many new features are introduced in this new database, but some minor errors are also introduced in the mail sending method.

1. send an email

Before discussing these small errors in detail, let's take a look at an example.Code(Assume that you have added "using system. net. Mail" to the file "):

Mailmessage MSG = new mailmessage ();
MSG. From = new mailaddress ("address@domain.com", "person's name ");
MSG. to. Add (New mailaddress ("destination@domain.com", "Addressee's name ");
MSG. to. Add (New mailaddress ("destination2@domain.com", "Addressee 2's name ");
MSG. Subject = "Message Subject ";
MSG. Body = "mail body content ";
MSG. isbodyhtml = true;
MSG. Priority = mailpriority. High;
Smtpclient c = new smtpclient ("mailserver.domain.com ");
C. Send (MSG );

The above code is not much different from the implementation in previous versions. It only makes some minor changes when the message is specified. You don't have to build an address on your own. You can make the system work for you. If you specify an email address and a name, it automatically displays the following content in the message:

"Person's name" <destination@domain.com>

This is exactly the "correct" format of an email address. Of course, you can add multiple addresses to the to, CC, and BCC sets in the same way as above. This programming method is much easier to send a large number of messages than to send each message separately-you only need to add multiple addresses to the BCC attribute to implement mass mailing.

Ii. Existing Problems

Now, let's analyze the small errors.

As mentioned above, this new namespace contains some minor errors. First, when you send an email, the mail header information is all added in lowercase letters. However, the SMTP mail RFC specification does not specify how the mail header should be capitalized; however, many junk mail FiltersProgramHowever, it limits the incorrect upper-case email messages in the header.

Another error is related to priority settings-through priority settings, you can specify the importance of a message on the mail client. Because of this formatting method of the mail header (all converted to lowercase), my mail program (Eudora) cannot identify the corresponding priority mark, therefore, the importance of this email is not specified. Although this seems trivial, it seems that there is no obvious reason to switch to the new version of system. Web. Mail.

Therefore, I will continue to discuss this issue. If I cannot find a good remedy, I just need to go back to the previous system. Web. Mail to solve the above warning problem more effectively.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.