On the homepage, the SMTP service must be enabled for the sender's mailbox.
/// <Summary> /// send the email /// </Summary>
/// <Param name = "from"> sender's email address </param>
/// <Param name = "to"> recipient's email address </param>
/// <Param name = "subject"> subject </param>
/// <Param name = "isbodyhtml"> whether it is HTML </param>
/// <Param name = "body"> body </param>
/// <Param name = "smtphost"> SMTP server address </param>
////// <Param name = "username"> email user name </param>
////// <Param name = "password"> email password </param>
/// <Returns> Successful </returns>
Public static bool send (string from, string to, string subject, bool isbodyhtml, string body, string smtphost, string username, string password)
{
String [] Ts = to. Split (',');
Bool issuccess = true;
Foreach (string t in ts)
{
Try
{
Mailmessage Mm = new mailmessage ();
Mm. From = new mailaddress (from );
Mm. to. Add (New mailaddress (T. Trim ()));
Mm. Subject = subject;
Mm. isbodyhtml = isbodyhtml;
Mm. Body = body;
Smtpclient SC = new smtpclient ();
SC. Host = smtphost;
SC. usedefacrecredentials = true; // winform is not affected. Asp.net, false indicates that the strict identity information is not sent.
// Smtpclient. enablessl = true; // if the server does not support SSL, a security connection error is reported.
SC. Credentials = new system. net. networkcredential (username, password );
SC. deliverymethod = smtpdeliverymethod. Network;
SC. Send (mm );
}
Catch
{
Issuccess = false;
}
}
Return issuccess;
}