VS2005 (asp.net2.0) easy to send mail. __.net

Source: Internet
Author: User
Tags mailmessage smtpclient

VS2005 (asp.net2.0) easy to send mail.

In asp.net 2.0 it is easy to develop SMTP email messages. Unlike an ASP, you have to register JMail controls or something.

You need to reference the following namespaces:
Using System.Net.Mail;
Using System.Net;


The following is a message sent via smtp.126.com. Smtp.126.com requires authentication.
protected void Sendmail_click (object sender, EventArgs e)
{
String to = "xpnew@126.com";
String from = "xpnew@126.com";
String subject = mailtitle.text;//"Using the new SMTP client.";
String BODY = mailbody.text;//@ ' Using This new feature, your can send an e-mail message from a application very easily. ";
MailMessage message = new MailMessage (from, to, subject, body);
SmtpClient client = new SmtpClient ("smtp.126.com", 25);
Credentials are necessary if the server requires the client
To authenticate before it'll send e-Mail on the client ' s behalf.
Client. Credentials = credentialcache.defaultnetworkcredentials;
Client. Credentials = new NetworkCredential ("Xpnew", "xxxxxx");//This is changed to your own account and password.
Client. Send (message);
}

The following


is sent through the native (IIS-brought SMTP server) without authentication.
This is also useful, usually in the actual work encountered in the development of the Enterprise internal Web applications (such as OA), then have to use the internal SMTP server.
It's a pity that I didn't pass the test all afternoon. (Cannot relay to the Internet)
    protected void Sendfromlocal_click (object sender, EventArgs e)
     {
        string to = ' xpnew@126.com ';
        string from = "xpnew@126.com";
        String subject = mailtitle.text;//"Using the new SMTP client.";
        String BODY = mailbody.text;//@ ' Using This new feature, your can send an E Mail message from a application very easily. ";
        MailMessage message = new MailMessage (from, to, subject, body);
        SmtpClient client = new SmtpClient ("localhost");

Credentials are necessary if the server requires the client
To authenticate before it'll send e-Mail on the client ' s behalf.
Client. Credentials = credentialcache.defaultnetworkcredentials;
Client. Send (message);
}

There may be some problems when sending through this machine.
1, "Mailbox is not available." Server response: 5.7.1 Unable to relay for xpnew@126.com "
Solution:
In IIS, right-click the default SMTP virtual server, select Properties, switch to the Access page, click the "Relay" button, and in the pop-up box, select "Except the list below" to determine.
2, the mail sent out, but the other side is not received.
The reason for the moment has not been found. Looked up some information on the Internet, as if the other side of the server was identified as spam.


Resources:

1, Msdn:.net Framework class Library Smtpclient.credentials properties

2, vs2003 and vs2005 send SMTP mail (downmoon original)
Http://dev.21tx.com/2006/01/22/10217.html

3, Error: 5.7.1

Http://blog.csdn.net/beimuaihui/archive/2007/08/12/1739409.aspx

4. Configure remote domains for Internet information Services SMTP mail relay servers in Win2003
Http://www.knowsky.com/341533.html


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.