ASP. NET outbound mail

Source: Internet
Author: User
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>");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.