The first code can only send a message without SMTP authentication, but now a lot of email sent need to verify, and then look for the next MSDN Help, found the code to send the verification, posted out hope for everyone to help!
Copy Code code as follows:
public static int SendMail (string to, string body,string subject)
{
Try
{
int ncontain = 0;
Add Sender Address
String from = "Your send email";
MailMessage MAILMSG = new MailMessage ();
Mailmsg.from = new MailAddress (from);
Ncontain + = MailMsg.From.Address.Length;
Add recipient Address
MAILMSG.TO.ADD (to);
Ncontain + = MailMsg.To.ToString (). Length;
Add Message subject
Mailmsg.subject = Subject;
mailmsg.subjectencoding = Encoding.UTF8;
Ncontain + = MailMsg.Subject.Length;
Add message Content
Mailmsg.body = body;
mailmsg.bodyencoding = Encoding.UTF8;
Mailmsg.isbodyhtml = true;
Ncontain + = MailMsg.Body.Length;
if (mailmsg.isbodyhtml = = True)
{
Ncontain + 100;
}
Send mail
Try
{
Define the client that sends the message
SmtpClient client = new SmtpClient ();
Represents authentication with the default credentials of the currently logged-on user
Client. useDefaultCredentials = true;
Include user name and password
Client. Credentials = new System.Net.NetworkCredential (application. Getapplicationsendmail (), application. Getapplicationsendpass ());
Set the IP address of the mail server host
Client. Host = "SMTP server IP"
Set port for mail server
Client. Port = 25;
Configure properties for sending messages
Client. Deliverymethod = Smtpdeliverymethod.network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage (strfrom, Strto, Strsubject, strbody);
mailmsg.priority = System.Net.Mail.MailPriority.Normal;
Client. useDefaultCredentials = false;
Send mail
Client. Send (MAILMSG);
return 1;
}
catch (Exception ex) {return 0;}
}
catch (Exception ex) {return 0;}
}