| 发表于:2007-08-21 16:25:014楼 得分:10 |
public static bool send(string emailto, string subject, string content) { bool success = true; #region --- 用system.net.mail发送邮件 --- #region --- 发送邮件的相关信息设置 --- string host = configurationmanager.connectionstrings[ "host "].tostring(); //邮件服务器 string emailuser = configurationmanager.connectionstrings[ "fromuser "].tostring(); //发件人邮箱登录帐号 string emailpassword = configurationmanager.connectionstrings[ "fromcode "].tostring(); //发件人邮箱登录密码 string emailfrom = configurationmanager.connectionstrings[ "from "].tostring(); //发件人邮箱 #endregion if (emailto == " " ¦ ¦ emailto == null) { success = false; } else { system.net.mail.smtpclient client = new smtpclient(); client.host = host; client.usedefaultcredentials = false; client.credentials = new system.net.networkcredential(emailuser, emailpassword); client.deliverymethod = smtpdeliverymethod.network; system.net.mail.mailmessage message = new mailmessage(emailfrom, emailto); message.subject = subject; //邮件标题 message.body = content; //邮件内容 message.bodyencoding = system.text.encoding.utf8; message.isbodyhtml = true; try { client.send(message); } catch (exception ex) { success = false; } } return success; | | |
|