Asp.net email sending code (solution with Errors 0 × 80040217 and 530)

Source: Internet
Author: User

There are a lot of such code on the Internet, so I will not introduce the classes in detail here. Here is an incorrect solution:

1. 0x80040217. The server response was not available

The Sina SMTP service I used does not exist when the POP/SMTP service in your sina mailbox is enabled.

Specific path: Mailbox settings-> account-> POP/SMTP settings-> enable

2. 530 authentication required

The user name and password of the email you used are not provided.

// Basic permission <br/> objmailmessage. fields. add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); </P> <p> // user name <br/> objmailmessage. fields. add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "mytest110"); </P> <p> // password <br/> objmailmessage. fields. add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "mytest110 ");

 

All code:

 

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. mail;

Namespace mailsender
{
Public partial class default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}

Protected void button#click (Object sender, eventargs E)
{
Mailmessage objmailmessage;
Mailattachment objmailattachment;

// Create an attachment object
Objmailattachment = new mailattachment ("C: // 1.xml"); // attachments for sending emails

// Create an email message
Objmailmessage = new mailmessage ();
Objmailmessage. From = "mytest110@sina.com"; // source email address
Objmailmessage. To = "********* @ QQ.com"; // target email address
Objmailmessage. Subject = "mail title: Hello"; // The Mail title
Objmailmessage. Body = "mail sender content: test whether the email is successfully sent! "; // Content of the email
Objmailmessage. attachments. Add (objmailattachment); // attaches the attachment to the mail message object.

// Use Sina's SMTP to send emails. You need to use Microsoft. NET Framework SDK V1.1 and later versions.
// Basic Permissions
Objmailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1 ");

// User Name
Objmailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "mytest110 ");

// Password
Objmailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword ","******");

// If the preceding three lines of code are not available, the following error message is displayed: the server rejects one or more recipient addresses. Server Response: 530 authentication required

// SMTP address
Smtpmail. smtpserver = "smtp.sina.com ";

// Start sending emails
// Before sending the email, go to Sina mail to Enable POP/SMTP settings-> account-> POP/SMTP settings-> enable
// Otherwise, error 0x80040217. The server response was not available will be reported
Smtpmail. Send (objmailmessage );
}
}
}

 

PS: * set your own data

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.