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