[英]ASP Sending E-mail with CDOSYS and AJAX
我嘗試在IIS 7服務器中使用CDOSYS和AJAX發送電子郵件。 我已經發送了一個AJAX請求來發送郵件。 並且AJAX返回200 OK狀態。 但是電子郵件沒有到達。 誰能解決我的問題? 非常感謝!
我有3個文件:
1. index.html
2. main.js
function sendEmailAjaxFunc(){
var cusName = document.getElementById("cusName").value;
var emailAdr = document.getElementById("emailAdr").value;
var xmlhttp;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e){
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.open("GET","sendEmail.asp?cusName="+cusName+"&emailAdr="+emailAdr+"&sTime="+new Date().getTime(),true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//finish report
//alert(xmlhttp.responseText);
}
}
xmlhttp.send(null);
return true;
}
3. sendEmail.asp
<%@ Language=JScript CodePage=65001 %>
<%
var cusName = Request.QueryString("cusName");
var emailAdr = Request.QueryString("emailAdr");
var objMail = Server.CreateObject( "CDO.Message" );
objMail.BodyPart.charset = "unicode-1-1-utf-8";
objMail.From = 'info@it.com';
objMail.To = emailAdr;
objMail.Cc = emailAdr;
objMail.Subject = 'It-Zhai GmbH';
objMail.TextBody = 'Hello ' + cusName + ', just a text email';
//objMail.HTMLBody = 'HTML';
//objMail.AddAttachment('justAttachment.txt');
objMail.SendMail;
%>
您是否設置了電子郵件服務器來發送消息? 看來您需要配置要通過服務器發送的消息。
這里有一些其他選項可添加到您的配置中...
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server'
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"
'Server port (typically 25)'
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.Configuration.Fields.Update
您可以在此處找到更多信息... http://www.paulsadowski.com/wsh/cdo.htm
謝謝朋友!
我找到了解決方案。 終於從我的服務器發送了一封電子郵件。 在文件sendEmail.asp中,我應該進行以下配置:
var oServer=new ActiveXObject("CDO.Configuration");
oServer.Fields(cdoSMTPServer)="..."; //Server Adresse
oServer.Fields(cdoSMTPAuthenticate) = 1;
oServer.Fields(cdoSMTPUseSSL) = 1;
oServer.Fields(cdoSendUsername)="...";
oServer.Fields(cdoSendPassword)="...";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.