Tutorial: ASP. NET with QQ, NetEase to send mail and add attachments
This is my QQ mailbox to appear in the exception:
The command order is incorrect. The server responds as: Error:need EHLO and AUTH first!
Unable to read data from the transport connection: net_io_connectionclosed
Workaround:
First go to the mailbox to set the content:
1. Turn on SMTP,
2. Request Authorization Code. (The authorization code is used as the QQ mailbox login password.)
If this is done, there should be a problem with the code. Please refer to the C # code section.
QQ Email Code:
Note: The user name does not have the suffix "@qq. com", the password uses the generated authorization code, and SSL is set to True
Method One:
(Environment: vs2015 MVC, tested successfully)
Webmail.smtpserver = "smtp.qq.com"; Webmail.smtpport = 587; Webmail.enablessl = true; Webmail.username = "8448xx4"; Webmail.password = "Ujalggwrqpvdbghi"; Webmail.from = "[email protected]";//Gets or sets the sender's e-mail address webmail.send (to, subject,content "); This method has many overloads to refer to the MSDN Library //to 1: The recipient's e-mail address. //subject2: Message header //content3. Text
Method Two
String txtfullpath = HttpContext.Current.Server.MapPath ("~/") [email protected] "show/xx contract. txt"; Create an Attachment object Attachment objmailattachment = new Attachment (Txtfullpath); Create mail message MailMessage objmailmessage = new MailMessage (); Objmailmessage.from = new MailAddress ("[email protected]"); Source mail address recipient objMailMessage.To.Add (Usermail); Objmailmessage.subject = "Event notification!" ";///Send the title of the message//Attach the attachment to the mail message object ObjMailMessage.Attachments.Add (objmailattachment); Body Objmailmessage.body = "Please be in 2016 on building sixth."; Objmailmessage.isbodyhtml = true; SmtpClient smptpmail = new SmtpClient (); Set the SMTP server for the Outbox smptpmail.host = "smtp.qq.com";//ssl is set to true Smptpmail.enablessl = true; Port used by SMTP Smptpmail.port = 587; QQ user name, and authorization code smptpmail.credentials = new NetworkCredential ("8448xx4", "gsdahhe!"); Smptpmail.send (Objmailmessage);
NetEase mailbox: (Has been tested successfully, PS.) I netease mailbox does not seem to have set the Stmap and authorization code, it seems that the account, password can be used directly)
String txtfullpath = HttpContext.Current.Server.MapPath ("~/") [email protected] "show/xxx contract. txt"; Create an Attachment object Attachment objmailattachment = new Attachment (txtfullpath); Create mail message mailmessage objmailmessage = new MailMessage (); Objmailmessage.from = new MailAddress ("[email protected]"); Source mail address objMailMessage.To.Add (usermail);//recipient Objmailmessage.subject = "Event notification! ";///Send the title of the message //Attach the attachment to the mail message object objMailMessage.Attachments.Add (objmailattachment); Body objmailmessage.body = body,//// objmailmessage.isbodyhtml = true; SmtpClient smptpmail = new SmtpClient (); Set the SMTP server for outbox smptpmail.host = "smtp.163.com"; The port used by SMTP smptpmail.port =; Username password smptpmail.credentials = new NetworkCredential ("[Email protected]", "454646546SDSG"); Smptpmail.send (Objmailmessage);
ASP. NET with QQ, NetEase send mail and add attachments