EWS:邮件已添加到已发送邮件但未发送
问题描述:
我正在使用Microsoft Exchange Web服务 - EWS托管API 2.2从我的Exchange Server电子邮件发送邮件。 下面是我使用的代码:EWS:邮件已添加到已发送邮件但未发送
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials("UserName", "Password", "domain");
service.Url = new Uri("https://exchangeserver.com/EWS/Exchange.asmx");
EmailMessage email = new EmailMessage(service);
//email.ToRecipients.Add("[email protected]");
email.ToRecipients.Add("[email protected]");
email.ToRecipients.Add("[email protected]");
email.Body = new MessageBody("BODY!");
email.SendAndSaveCopy();
//Here is my Certificate Validation function taken straight from MSDN :
static private bool CertificateValidationCallBack(object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
// If the certificate is a valid, signed certificate, return true.
if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
{
return true;
}
// If there are errors in the certificate chain, look at each error to determine the cause.
if ((sslPolicyErrors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)
{
if (chain != null && chain.ChainStatus != null)
{
foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)
{
if ((certificate.Subject == certificate.Issuer) && (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))
{
// Self-signed certificates with an untrusted root are valid.
continue;
}
else
{
if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
{
// If there are any other errors in the certificate chain, the certificate is invalid,
// so the method returns false.
return false;
}
}
}
}
// When processing reaches this line, the only errors in the certificate chain are
// untrusted root errors for self-signed certificates. These certificates are valid
// for default Exchange server installations, so return true.
return true;
}
else
{
// In all other cases, return false.
return false;
}
}
如果我设置ToEmailAddress作为登录用户名本身,邮件被发送到收件箱。 如果我发送到任何其他电子邮件地址(尝试Gmail,Hotmail,雅虎),邮件存放在发送的邮件,但它没有传递到预期的电子邮件地址。 但是,如果我登录到Outlook Web App并键入邮件并发送,则邮件将添加到已发送邮件以及发送到配方邮件地址。
我检查过垃圾邮件/垃圾邮件文件夹等。凭据是正确的,因为我能够保存已发送邮件中的邮件副本。
这是什么,我做错了?
答
事实证明,邮件被垃圾邮件发送出站交换服务器本身。如果我设置了一个有意义的主题,邮件正在发送。
email.Subject = "Some meaningful subject";
我会通过检查邮件跟踪https://technet.microsoft.com/en-us/library/bb124375%28v=exchg.150%29.aspx开始,你也可以启用跟踪并查看导致您从服务器回来并检查CAS服务器上的EWS日志文件 –