通过CDOSYS发送电子邮件但用C#编写

时间:2012-01-31 05:49:30

标签: asp.net asp-classic

我厌倦了我的托管公司。我想你可以帮助我。

我很简单地需要用Classic ASP编写完整的网站。现在我想要一个使用CDOSYS发送电子邮件的页面。我希望从托管公司的ASP中获取该脚本,我应该拥有什么样的设置。他们总是用C#发给我代码。

这里是他们总是发送:

CDOSYS是System.Web.Mail命名空间的一部分,默认安装在Windows 2000和Windows XP平台上。它取代了用于发送SMTP电子邮件的CDONTS,可以与我们的IIS 6和IIS 7 Windows主机帐户一起使用。以下代码示例演示了如何创建,格式化和发送电子邮件。

private void SendEmail()
{
const string SERVER = "relay-hosting.secureserver.net";
MailMessage oMail = new System.Web.Mail.MailMessage();
oMail.From = "emailaddress@domainname";
oMail.To = "emailaddress@domainname";
oMail.Subject = "Test email subject";
oMail.BodyFormat = MailFormat.Html; // enumeration
oMail.Priority = MailPriority.High; // enumeration
oMail.Body = "Sent at: " + DateTime.Now;
SmtpMail.SmtpServer = SERVER;
SmtpMail.Send(oMail); 
oMail = null; // free up resources
 } 

这是我写的ASP,它使用相同的东西,但不起作用:

Set objCDOSYSMail = Server.CreateObject("CDO.Message") 
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration") 

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net" 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
objCDOSYSCon.Fields.Update 
With objCDOSYSMail
  .To       = strEmail
  .BCc       = "a@gmail.com"
  .Cc       = "b@gmail.com"
  .From     = "sales@b.com"
  .Subject  = "Thank you!"
  .HTMLBody = "Hello<br></br><h3>Thank you for your enquiry. <br/>"
Set objCDOSYSMail = Nothing 
Set objCDOSYSCon = Nothing 

我不知道如何使用他们的代码....请帮助

1 个答案:

答案 0 :(得分:0)

您可以在传统ASP页面中使用以下代码来发送带有CDOSYS的电子邮件:

Set objMail = Server.CreateObject("CDO.Message")
Set objConf = Server.CreateObject("CDO.Configuration")
Set objFlds = objConf.Fields
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.your-site-url.com" 'your smtp server domain or IP address goes here
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'default port for email
'uncomment next three lines if you need to use SMTP Authorization
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
objFlds.Update
objMail.Configuration = objConf
objMail.FromName = "Your Name"
objMail.From = "your@address.com"
objMail.To = "destination@address.com"
objMail.Subject = "Email Subject Text"
objMail.TextBody = "The message of the email..."
objMail.Send
Set objFlds = Nothing
Set objConf = Nothing
Set objMail = Nothing