看过一篇这方面的文章,网址如下:
http://www.cnblogs.com/dsclub/archive/2005/02/04/102082.aspx
对这里登陆SMTP的一段不明白,而且我的机器总是提示“未能访问‘CDO.Message’对象。”我的机器装的是2003 Server,还请各位高手指点!!!
http://www.cnblogs.com/dsclub/archive/2005/02/04/102082.aspx
对这里登陆SMTP的一段不明白,而且我的机器总是提示“未能访问‘CDO.Message’对象。”我的机器装的是2003 Server,还请各位高手指点!!!
using System.Web.Mail;
using System.Text;
using Com.iFlytek.Utility;
using iFlytek.iAvp.Access ;
using System.Configuration;
namespace FeeCommon
{
/// <summary>
/// 邮件发送类。
/// </summary>
public class Email
{ string MyMailFrom;
string EmailServer;
string EmailName;
string EmailPassword;
string AdminEmail;
string SendToAdmin;
public static AppSettingsReader cfg = new AppSettingsReader();
public Email()
{
MyMailFrom= (string)cfg.GetValue("MyMailFrom" , typeof(string) );
EmailServer= (string)cfg.GetValue("SmtpServer" , typeof(string) );
EmailName= (string)cfg.GetValue("EmailName" , typeof(string) );
EmailPassword= (string)cfg.GetValue("EmailPassword" , typeof(string) );
AdminEmail=(string)cfg.GetValue("AdminEmail" , typeof(string) );
SendToAdmin=(string)cfg.GetValue("SendToAdmin" , typeof(string) );
}
public bool SendEmail(string From , string To , string subject ,string Body,string sSubstr )
{ MailMessage MyMail = new MailMessage();
MyMail.From = MyMailFrom;
MyMail.To = To;
MyMail.Subject =subject;
MyMail.Body = " ";
//判断是否每一封邮件都要发一份到管理员邮箱
if(SendToAdmin=="yes")
MyMail.Cc = AdminEmail;
//MyMail.Bcc = sBcc;
//MyMail.UrlContentBase = sUrlContentBase;
//MyMail.UrlContentLocation = sUrlContentLocation;
MyMail.BodyEncoding = Encoding.Unicode;
MyMail.BodyFormat = MailFormat.Text; MyMail.Priority = MailPriority.High;
if(sSubstr!="")
{
MailAttachment MyAttachment = new MailAttachment(sSubstr);
MyMail.Attachments.Add(MyAttachment);
}
MyMail.Headers.Add("iFlytek", "www.iflytek.com" );
MyMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
MyMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", EmailName); //set your username here
MyMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",EmailPassword); //set your password here SmtpMail.SmtpServer =EmailServer;
try
{
SmtpMail.Send(MyMail);
Console.WriteLine("{0}邮件发送成功" ,subject);
return true;
}
catch(Exception ex)
{
Log.WriteToFile("",subject+"邮件发送失败");
Console.WriteLine("{0}邮件发送失败"+ex.Message.ToString(), subject);
return false;
}
}
}
}
用我的这个类吧 我自己用没有问题的
using iFlytek.iAvp.Access;
这两句编译时有问题,怎么样设置?
谢谢.
[email protected]
[email protected]