发邮件,用的是.net2005 调用的是cdo。发信时偶尔,在subject中出现=?utf-8?Q?这样的乱码,邮件正文正常显示。不知道是什么原因,渴求高人指点,多谢调用函数的代码如下:
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mailServer"></param>
        /// <param name="fromEmail"></param>
        /// <param name="toEmail"></param>
        /// <param name="ccEmail"></param>
        /// <param name="subject"></param>
        /// <param name="body"></param>
        public void SendMail_HTML(string mailServer, string fromEmail, string toEmail, string ccEmail, string subject, string body, string ppporvpp, int alertid)
        {
            if ((toEmail == "") && (ccEmail == ""))
                return;            // create mail message object
            MailMessage mail = new MailMessage();
            mail.From = fromEmail;           // put the from address here
            mail.To = toEmail; // put to address here
            mail.Cc = ccEmail;
            mail.Subject = subject; // put subject here
            mail.Body = body; // put body of email here
            mail.BodyFormat = MailFormat.Html;
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            SmtpMail.SmtpServer = mailServer; // put smtp server you will use here 
            //send the mail
            try
            {
                SmtpMail.Send(mail);
                //log info
                Console.WriteLine("Send a email subject:" + subject + " to " + toEmail + " succeeded.");
                if (ppporvpp == "ppp")
                {
                    LogEvent.WriteLogPPP("Send a email subject:" + subject + " to " + toEmail + " succeeded.");
                }
                else if (ppporvpp == "vpp")
                {
                    LogEvent.WriteLogVPP("Send a email subject:" + subject + " to " + toEmail + " succeeded.");
                }                if (alertid > 0)
                {
                    int ret = DBManager.UpdateAllAlertHistory(DateTime.Now, 1, alertid, ppporvpp.ToUpper());
                }
            }
            catch (Exception err)
            {
                if (ppporvpp == "ppp")
                {
                    LogEvent.WriteLogPPP("Send a email subject:" + subject + " to " + toEmail + " failed." + err.Message);
                }
                else if (ppporvpp == "vpp")
                {
                    LogEvent.WriteLogVPP("Send a email subject:" + subject + " to " + toEmail + " failed." + err.Message);
                }                Console.WriteLine("Send a email subject:" + subject + " to " + toEmail + " failed." + err.Message);                if (alertid > 0)
                {
                    int ret = DBManager.UpdateAllAlertHistory(DateTime.Now, 0, alertid, ppporvpp.ToUpper());
                }
            }
        }

解决方案 »

  1.   

    这问题应该可以解决的。不过我当时写代码的时间用了以下4中方法
    1。.net的sendmail(),但是不支持认证服务。一般不会成功
    2. 采用.net调用oe发送界面,当然你需要配置好你的smtp
    3.采用.net和system32下的cdo方式发送邮件。支持认证服务。不过可以移植空间不大,和系统连接太紧密
    4.采用.net编写dll的方式。socket,支持多地址多附件的发送。不过在连接时间上用的时间比其他前几种多。。
    如果你需要的话,我可以给你,发送和接受邮件,支持smtp和pop3。
      

  2.   

    我的联系方式是124154024 或者[email protected]