刚新接手一个网站,里面有一个发送E-mail的页面。现在客户那边说现在发不了E-mail了。我菜鸟一个。从来没做过B/S结构的东西。刚来公司才一个多月。请个位大侠帮看看:源码如下:
using System;
using System.Web;namespace EMailCommon
{
/// <summary>
/// Summary description for CDOSendMail.
/// </summary>
public class CDOSendMail
{
public CDOSendMail()
{
//
// TODO: Add constructor logic here
//
}
public static void sendMail(string mailFrom, string mailTo, string mailSubject, string mailBody)
{
try
{
CDO.Message oMsg = new CDO.Message();
oMsg.From = mailFrom; //"[email protected]";
oMsg.To = mailTo; //"[email protected]";
oMsg.Subject = mailSubject; // "MailTest";
oMsg.HTMLBody = mailBody; // "<html><body>Test</body></html>"; CDO.IConfiguration iConfg = oMsg.Configuration;
ADODB.Fields oFields = iConfg.Fields;
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value= mailFrom; //sender mail
oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value= mailTo; //email account
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="[email protected]";
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="3308576636"; oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
//value=0 代表Anonymous验证方式(不需要验证)
//value=1 代表Basic验证方式(使用basic (clear-text) authentication.
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value= "smtp.fabby.com";
//"smtp.21cn.com"; oFields.Update();
oMsg.BodyPart.Charset="ISO-8859-1";
oMsg.HTMLBodyPart.Charset="ISO-8859-1"; oMsg.Send();
oMsg = null;
}
catch (Exception e)
{
throw e;
}
}
}
}
using System;
using System.Web;namespace EMailCommon
{
/// <summary>
/// Summary description for CDOSendMail.
/// </summary>
public class CDOSendMail
{
public CDOSendMail()
{
//
// TODO: Add constructor logic here
//
}
public static void sendMail(string mailFrom, string mailTo, string mailSubject, string mailBody)
{
try
{
CDO.Message oMsg = new CDO.Message();
oMsg.From = mailFrom; //"[email protected]";
oMsg.To = mailTo; //"[email protected]";
oMsg.Subject = mailSubject; // "MailTest";
oMsg.HTMLBody = mailBody; // "<html><body>Test</body></html>"; CDO.IConfiguration iConfg = oMsg.Configuration;
ADODB.Fields oFields = iConfg.Fields;
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value= mailFrom; //sender mail
oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value= mailTo; //email account
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="[email protected]";
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="3308576636"; oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
//value=0 代表Anonymous验证方式(不需要验证)
//value=1 代表Basic验证方式(使用basic (clear-text) authentication.
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value= "smtp.fabby.com";
//"smtp.21cn.com"; oFields.Update();
oMsg.BodyPart.Charset="ISO-8859-1";
oMsg.HTMLBodyPart.Charset="ISO-8859-1"; oMsg.Send();
oMsg = null;
}
catch (Exception e)
{
throw e;
}
}
}
}
至于代码,只要google一下CDO,n多
Dim sMsg As String
Try sMsg = "dasfasdfsdafsdafdsafsd" Dim objEmail As New MailMessage objEmail.To = "[email protected]" objEmail.From = "[email protected]" objEmail.Subject = "insert" objEmail.Body = sMsg objEmail.BodyFormat = MailFormat.Text SmtpMail.SmtpServer = "smtp.163.com"
objEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1")
objEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "wtaoboy")
objEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "*****")
System.Threading.Thread.Sleep(1000) SmtpMail.Send(objEmail) Catch aa As Exception
MsgBox("dsfasfdsa")
End Try End Sub
没准能找到答案呢
oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=1;
谢谢大家的参与。