I personally wrote a jmail email to the class, and the test was successful.

Source: Internet
Author: User

Using system;
Using system. IO;

// Yang Chun
// 2008-6-8

/// <Summary>
/// Mail Summary
/// </Summary>
Public class mymail
{
String publicmail = system. configuration. configurationsettings. deleetask[ "publicmail"]. tostring ();
String pubicmmailpassword = system. configuration. configurationsettings. deleetask[ "publicmailpasword"]. tostring ();
String mailusername = system. configuration. configurationsettings. receivettings ["mailusername"]. tostring ();
Public mymail ()
{
//
// Todo: add the constructor logic here
//
}

/// <Summary>
/// Send an email
/// </Summary>
/// <Param name = "reciver"> recipient </param>
/// <Param name = "title"> topic </param>
/// <Param name = "content"> content </param>
/// <Param name = "attpath"> attachment </param>
/// <Returns> Successful </returns>
Public bool Sendmail (string reciver, String title, string content, string attpath)
{
Try
{
If ("" = attpath)
{
Return sendmailbyjmail (reciver, title, content );
}
Else
{
If (file. exists (attpath) = true)
{
Return sendmailbyjmail (reciver, title, content, attpath );

}
Else
{
Return sendmailbyjmail (reciver, title, content );
}
}
}
Catch (exception ex)
{
Return false;
Console. Write (ex. Message );
}

}

/// <Summary>
/// Send an email without attachment
/// </Summary>
/// <Param name = "reciver"> recipient </param>
/// <Param name = "title"> topic </param>
/// <Param name = "content"> content </param>
/// <Returns> Successful </returns>
///
Private bool sendmailbyjmail (string reciver, String title, string content)
{
Myjmail. messageclass jmailmessage = new myjmail. messageclass ();
Jmailmessage. charset = "gb2312 ";
Jmailmessage. Encoding = "base64 ";
Jmailmessage. contenttype = "text/html ";
Jmailmessage. isoencodeheaders = false;
Jmailmessage. Priority = convert. tobyte (1 );
Jmailmessage. From = publicmail;
Jmailmessage. fromname = mailusername;
Jmailmessage. Subject = title;
Jmailmessage. mailserverusername = getloginnamebyemail (publicmail );
Jmailmessage. mailserverpassword = pubicmmailpassword;
Jmailmessage. addrecipient (reciver ,"","");
Jmailmessage. Body = content;

If (jmailmessage. Send (getsmtpsererbyemail (publicmail), false ))
{
Return true;
}
Else
{
Return false;
}
}

/// <Summary>
/// Send an email with an attachment
/// </Summary>
/// <Param name = "reciver"> recipient </param>
/// <Param name = "title"> topic </param>
/// <Param name = "content"> content </param>
/// <Param name = "attpath"> attachment path </param>
/// <Returns> Successful </returns>
Private bool sendmailbyjmail (string reciver, String title, string content, string attpath)
{
Myjmail. messageclass jmailmessage = new myjmail. messageclass ();
Jmailmessage. charset = "gb2312 ";
Jmailmessage. Encoding = "base64 ";
Jmailmessage. contenttype = "text/html ";
Jmailmessage. isoencodeheaders = false;
Jmailmessage. Priority = convert. tobyte (1 );
Jmailmessage. From = publicmail;
Jmailmessage. fromname = mailusername;
Jmailmessage. Subject = title;
Jmailmessage. mailserverusername = getloginnamebyemail (publicmail );
Jmailmessage. mailserverpassword = pubicmmailpassword;
Jmailmessage. addrecipient (reciver ,"","");
Jmailmessage. addattachment (attpath, true, attpath. substring (attpath. lastindexof (".") + 1, 3 ));
Jmailmessage. Body = content;

If (jmailmessage. Send (getsmtpsererbyemail (publicmail), false ))
{
Return true;
}
Else
{
Return false;
}
}

///


// obtain the logon name based on the email address
///
// email
// logon name
private string getloginnamebyemail (string email)
{< br> string loginname = Email. substring (0, email. indexof ("@");
return loginname;
}

/// <Summary>
/// Obtain the SMTP server address by email
/// </Summary>
/// <Param name = "email"> email </param>
/// <Returns> stmp server address </returns>
Private string getsmtpsererbyemail (string email)
{
Int length = Email. length;
String smtpserver = "SMTP." + email. substring (email. indexof ("@") + 1, length-email. lastindexof ("@")-1 );
Return smtpserver;
}

}

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.