阿尔海南粉 发表于 2015-9-11 11:38:21

在局域网向Exchange发送邮件

  普通的邮件, 用System.Net.Mail 类 或 System.Web.Mail 类 处理即可, 但是Exchange Server 环境下, 这两个类起不了作用-------至少目前我看到的情况如此.
  整个过程如下:
  1. 先添加COM 引用 "Microsoft CDO for Windows 2000 Library" .
2. 发送邮件的代码:


http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gifCDO.Message msg = new CDO.Message();
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      string passWord="passWord";
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      string from = "my@domain.com";
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      string server = "192.168.0.0";
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      msg.From = from;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      msg.To = from;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      msg.Subject = "test mail";
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      msg.TextBody = "test.";
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      CDO.IConfiguration iConfig = msg.Configuration;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      ADODB.Fields fields = iConfig.Fields;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = from;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = passWord;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = server;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      fields.Update();
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      try
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/ExpandedBlockStart.gifhttp://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/ContractedBlock.gif      http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/dot.gif{
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif            msg.Send();
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif            msg = null;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/ExpandedBlockEnd.gif      }
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif      catch (Exception ex)
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/None.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/ExpandedBlockStart.gifhttp://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/ContractedBlock.gif      http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/dot.gif{
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif            throw;
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/InBlock.gif
http://onexin.iyunv.com/source/plugin/onexin_bigdata/file:///D:/aaaaaaaa/向EXCHANGE发送邮件/用C#(ASP_Net)在Exchange%20Server环境下发送邮件%20-%20木刀s博客%20-%20博客园_files/ExpandedBlockEnd.gif      }



CDO.Message   CMail   =   new   CDO.Message();   
//设置configuration对象信息   
CDO.Configuration   cf   =   new   CDO.ConfigurationClass();   
//设置sendusing属性   
cf.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value   =   CDO.CdoSendUsing.cdoSendUsingPort;   
cf.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value   =   25;   
cf.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value   =   clsStaticVar.ExchangeIP;   
cf.Fields.Update();   
CMail.Configuration   =   cf;   
//添加邮件回持   
if   (chkMDN.Checked)   
CMail.MDNRequested   =   true;   
//添加送达回执   
if   (chkSended.Checked)   
CMail.DSNOptions   =   CDO.CdoDSNOptions.cdoDSNSuccessFailOrDelay;   
//设置编码   
CMail.BodyPart.Charset   =   CDO.CdoCharset.cdoGB2312;   
//发送人   
CMail.From   =   csm.userid   +   "@"   +   clsStaticVar.MailAddr;   
//接收人   
CMail.To   =   txtSendTo.Value;   
//抄送   
CMail.CC   =   txtCc.Value;   
//秘送   
CMail.BCC   =   txtMcc.Value;   
//主题   
if   (txtTitle.Value.Trim()   !=   "")   
CMail.Subject   =   txtTitle.Value;   
else   
CMail.Subject   =   "(无标题)";   
//CDO.IBodyPart   bp;   
//正文   
CMail.HTMLBody   =   Server.HtmlDecode(HTMLBody.Value);   
//优先级   
CMail.Fields["urn:schemas:httpmail:importance"].Value   =   ddlLevel.SelectedItem.Value;   
CMail.Fields.Update();   
//加附件   
System.IO.DirectoryInfo   di   =   new   DirectoryInfo(this.m_attrpath);   
System.IO.FileInfo[]   arr_fi   =   di.GetFiles();   
for   (int   i   =   0;   i   <   arr_fi.Length;   i++)   
{   
//防止加附件出错而中断   
try   
{   
CMail.AddAttachment(arr_fi.FullName,   "",   "");   
}   
catch{}   
}   
CMail.Send();
页: [1]
查看完整版本: 在局域网向Exchange发送邮件