[c#]代码库
public static string SendMail(string to, string toname, string body, int vbid)
{
string responseMsg = string.Empty;
try
{
DataTable dtBasic = new DataTable();
DBHelper.fnInsert.Read_VoteBasic(vbid, out dtBasic);
string mSubject = "请注意查看投票信息";
MailMessage m = new MailMessage();
m.From = new MailAddress("201103haozheng@edu2act.org", "投票通知");
m.To.Add(new MailAddress(to, toname));
if (dtBasic != null && dtBasic.Rows.Count.Equals(1))
{
mSubject = "关于 “" + dtBasic.Rows[0]["VTitle"] + "” 的投票信息";
body = "\r\n \r\n 信息简介:\r\n " + dtBasic.Rows[0]["VContent"] + "\r\n \r\n 截止日期:" + ((DateTime)dtBasic.Rows[0]["VDeadline"]).ToString("yyyy-MM-dd hh:mm") + " \r\n \r\n " + body;
}
m.Subject = mSubject;
m.Body = body;
SmtpClient client = new SmtpClient("email.edu2act.org");
client.Send(m);
responseMsg = "success";
}
catch (Exception ex)
{
responseMsg = "faild-" + ex.Message + ex.StackTrace;
//throw;
}
return responseMsg;
}