使用jamil发信
jmail.Message msg = new jmail.MessageClass();
msg.Silent = true;
msg.From = "andy@126.com ";
msg.AddRecipient( "andy@126.com ",null,null);
msg.MailServerUserName = "andy ";
msg.MailServerPassWord = "123456 ";
msg.Subject = "来自jamil的邮件 ";
msg.Body = "no message ";
msg.Send( "smtp.126.com ",true);
msg.Close();
这样能发出去吗?我发不出去。
是不是不能用别人的服务器?
还有,要是用.net自带的mail该怎么发送邮件呢?
------解决方案--------------------最好用自己的邮件服务器,另外,看看邮件端口是否开了
另外利用cdo发送邮件
/// <summary>
/// 发送邮件方法:基于Microsoft Outlook Collaborate Data Objects组件(COM组件)。使用互联网上Exchange Server的邮件服务器测试通过。
/// 当互联网不通时(即局域网内部),没有进行测试,有可能出现问题。
/// </summary>
/// <param name= "sSmtpServer "> 邮件服务器的IP地址 </param>
/// <param name= "sUserName "> 用户名 </param>
/// <param name= "sPassword "> 密码 </param>
/// <param name= "sFrom "> 发件人邮箱 </param>
/// <param name= "sTo "> 收件人地址(可以为多个,以“;”号分隔即可) </param>
/// <param name= "sCCTo "> 抄送人地址(可以为多个,以“;”号分隔即可) </param>
/// <param name= "sBCCTo "> 秘密抄送人地址(可以为多个,以“;”号分隔即可) </param>
/// <param name= "sSubject "> 邮件主题 </param>
/// <param name= "sContent "> 邮件内容 </param>
/// <param name= "sAttachmentUrlArray "> 附件Url地址数组(可以是本地的绝对路径,也可以是互联网Url。比如:http://www.microsoft.com/logo.gif) </param>
/// <returns> 发送成功返回True;否则false </returns>
public static bool SendOneMail(string sSmtpServer, string sUserName, string sPassword, string sFrom, string sTo, string sCCTo, string sBCCTo, string sSubject, string sContent, string[] sAttachmentUrlArray)
{
bool bResult=false;
CDO.Message oMsg=new CDO.MessageClass();
oMsg.From=sFrom; //发件人
oMsg.To =sTo; //收件人
oMsg.CC =sCCTo; //抄送人
oMsg.BCC =sBCCTo; //秘密抄送人
oMsg.Subject =sSubject; //邮件主题
oMsg.TextBody =sContent; //邮件内容
try
{
//存在附件时,添加附件
if(sAttachmentUrlArray.Length> 0)
{
for(int i=0;i <sAttachmentUrlArray.Length;i++)
{
oMsg.AddAttachment(sAttachmentUrlArray[i],sUserName,sPassword);
}
}
CDO.IConfiguration iConfig;
ADODB.Fields oFields;
iConfig = oMsg.Configuration;
oFields = iConfig.Fields;
oFields[ "http://schemas.microsoft.com/cdo/configuration/sendusing "].Value=2;
oFields[ "http://schemas.microsoft.com/cdo/configuration/sendemailaddress "].Value=sFrom;
oFields[ "http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress "].Value=sFrom;
oFields[ "http://schemas.microsoft.com/cdo/configuration/smtpaccountname "].Value=sUserName;
oFields[ "http://schemas.microsoft.com/cdo/configuration/sendusername "].Value=sUserName;
oFields[ "http://schemas.microsoft.com/cdo/configuration/sendpassword "].Value=sPassword;
oFields[ "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate "].Value=1;
oFields[ "http://schemas.microsoft.com/cdo/configuration/smtpserver "].Value=sSmtpServer;
oFields.Update();
oMsg.Send();