public class SendMail
{
public SendMail()
{
}
//发送普通文本Email方法入口
// From:发信人邮件地址 To:收信人邮件地址
// FromName:发信人名称 ToName:收信人名称
// Subject:信件主题
// Body:邮件正文
public int Send(string strTitle,string strTo,string strContent)
{
try
{
CDO.Message oMsg = new CDO.Message();
oMsg.From = "Administrator@innosis.com.cn";
oMsg.To = strTo;//"AtenShen@innosis.com.cn";
oMsg.Subject =strTitle;// "MailTest";
oMsg.HTMLBody = "<html><body>s"+strContent+"</body></html>";
CDO.IConfiguration iConfg = oMsg.Configuration;
ADODB.Fields oFields = iConfg.Fields;
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value="JamesWang"; //sender mail
oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value="JamesWang"; //email account
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="JamesWang";
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="531713Wt";
oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
//value=0 代表Anonymous验证方式(不需要验证)
//value=1 代表Basic验证方式(使用basic (clear-text) authentication.
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value="192.168.161.32";
oFields.Update();
oMsg.BodyPart.Charset="gb2312";
oMsg.HTMLBodyPart.Charset="gb2312";
oMsg.Send();
oMsg = null;
}
catch (Exception e)
{
return -1;
throw e;
}
return 0;
}
}