1 /// <summary>
2 // send the file as an attachment to the email
3 /// </Summary>
4 /// <Param name = "FILENAME"> file path </param>
5 // <Param name = "title"> title </param>
6 /// <returns> whether the message is sent successfully </returns>
7 public bool Sendmail (string filename, String title)
8 {
9 bool sendsuccess = false;
10 try
11 {
12 // all information is taken from the configuration file
13 configsettings setting = Global. getinstance (). settings;
14 // create an email
15 jmail. Message MSG = new jmail. messageclass ();
16 MSG. Logging = true;
17 // email sending Address
18 MSG. From = Setting. getstring (settingkey. mailaddress. tostring ());
19 // sender name
20 msg. fromname = Setting. getstring (settingkey. mailusername. tostring ());
21 // recipient's address
22 string readdress = Setting. getstring (settingkey. mailrecipientsaddress. tostring ());
23 // Recipient Name
24 string rename = (readdress. Split ('@') [0]. Trim ();
25 // Add a recipient to the email
26 msg. addrecipient (readdress, rename ,"");
27 // subject
28 MSG. Subject = title;
29 // Encoding
30 msg. charset = "gb2312 ";
31 // content
32 msg. Body = "";
33 // Add an attachment
34 msg. addattachment (filename, true ,"");
35 // obtain the sending information
36 string username = Setting. getstring (settingkey. mailusername. tostring ());
37 string Password = Setting. getstring (settingkey. mailpassword. tostring ());
38 string SMTP = Setting. getstring (settingkey. mailsmtpserveraddress. tostring ());
39 // sending information format: sender login mailbox User name: Login Password @ SMTP address (such as a: B @smtp.sohu.com)
40 string sendinfo = username. Trim () + ":" + password. Trim () + "@" + SMTP. Trim ();
41 // send
42 MSG. Send (sendinfo, false );
43 sendsuccess = true;
44}
45 catch (exception ex)
46 {
47 sendsuccess = false;
48 throw ex;
49
50}
51
52 return sendsuccess;
53
54}
Note: Add a reference file: Using jmail; version 4.3