c# exchange 邮件发送

 public static void SendExchangeMail(ServerMail serverMail, string subject, string content, string mailTo)
        {
            //获得要处理的邮件信
            try
            {
                LogHelper.WriteLog("发送邮件");
                string mailUser = serverMail.LoginUsers;
                string mailPass = serverMail.LoginPass;
                string mailFrom = serverMail.ServerEmail;
                string smtpserver = serverMail.SMTP;

                CDO.Message message = new CDO.Message();

                message.To = mailTo;
                message.TextBody = content;
                //邮件标题
                message.Subject = subject;
                message.From = mailFrom;
                message.Sender = mailFrom;
                CDO.IConfiguration iConfig = message.Configuration;

                ADODB.Fields fields = iConfig.Fields;

 

                fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;

                fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = mailFrom;

                fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = mailPass;

                fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;

                fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = smtpserver;

 

                fields.Update();

                message.Send();

                message = null;

 

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("处理邮件邮件异常", ex);
            }

        }

你可能感兴趣的:(C#)