String Myemail = Textbox1.text;
String Euser = Textbox2.text;
String Pass = Textbox3.text;
String Emailto = Textbox4.text;
String Title = Textbox5.text;
String Semail = Radiobuttonlist1.selectedvalue. tostring ();
String SMTP = Textbox6.text;
If (Semail = " 1 " )
{
Mailmessage mailmsg = New Mailmessage ();
// Set body format
Mailmsg. bodyformat = Mailformat. html;
// Set the recipient's email address
Mailmsg. = Emailto;
// Set the sender's email address
Mailmsg. From = Myemail;
// Set Email Subject
Mailmsg. Subject = Title;
// Set email content
Mailmsg. Body = " Test " ;
// Set to support server Verification
Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate " , " 1 " );
// Set User Name
Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendusername " , Euser );
// Set User Password
Mailmsg. Fields. Add ( " Http://schemas.microsoft.com/cdo/configuration/sendpassword " , Pass );
Try
{
// Set email sending server
Smtpmail. smtpserver = SMTP;
// Send email
Smtpmail. Send (mailmsg );
Response. Write ( " <SCRIPT> alert ('System. Web. Mail method sent successfully, please check it! '); </SCRIPT> " );
}
Catch (Exception ERR)
{
Response. Write ("System. Web. Mail method failed to send mail!" +Err. Message. tostring ());
}
}
Else
{
Jmail. Message jmail = New Jmail. Message ();
Datetime t = Datetime. now;
String subject = Title;
String body = " Test " ;
String fromemail = Myemail;
String toemail = Emailto;
// Silent attribute: If set to true, jmail will not throw an exception. jmail. Send () will return true or false Based on the operation results
Jmail. Silent = True ;
// Logs created by jmail. The prerequisite is that the loging attribute is set to true.
Jmail. Logging = True ;
// Character Set, "US-ASCII" by default"
Jmail. charset = " Gb2312 " ;
// Contentype of a letter. The default value is "text/plain"): If you send an email in HTML format, change it to "text/html.
Jmail. contenttype = " Text/html " ;
// Add recipient
Jmail. addrecipient (toemail, "" , "" );
Jmail. From = Fromemail;
// Sender email Username
Jmail. mailserverusername = Euser;
// Sender's email password
Jmail. mailserverpassword = Pass;
// Set Email Subject
Jmail. Subject = Subject;
// Add attachments to the email. (If there are multiple attachments, you can add jmail. addattachment ("C: \ test.jpg", true, null. [Note]: add an attachment to delete the above jmail. contenttype = "text/html. Otherwise, garbled characters will appear in the email.
// Jmail. addattachment ("C: \ test.jpg", true, null );
// Email content
Jmail. Body = " Test " ;
// Jmail sending Method
Jmail. Send (SMTP, False );
Jmail. Close ();
If (Jmail. Send (SMTP, False ) = True )
{
Response. Write ("<SCRIPT> alert ('jmail method is successfully sent. Please check it! '); </SCRIPT>");
}
Else
{
Response. Write ("<SCRIPT> alert ('jmail method failed to send mail! '); </SCRIPT>");
}
}