[英]Error sending email using CDO on port 587 (TLS)
Is there any trick to sending mail with CDO on port 587 (the port that uses TLS security protocol)?在端口 587(使用 TLS 安全协议的端口)上使用 CDO 发送邮件有什么技巧吗?
This is my C++ code:这是我的 C++ 代码:
CDO::IMessagePtr iMsg(__uuidof(CDO::Message));
CDO::IConfigurationPtr iConf = iMsg->GetConfiguration();
CDO::FieldsPtr iFields;
_bstr_t empty("");
iConf->Load(CDO::cdoIIS,empty); // this string constant from import
iFields = iConf->Fields;
iFields->Item["https://schemas.microsoft.com/cdo/configuration/smtpserver"]->Value = _variant_t(szServer);
iFields->Item["https://schemas.microsoft.com/cdo/configuration/smtpserverport"]->Value = _variant_t(587);
iFields->Item["https//schemas.microsoft.com/cdo/configuration/sendusing"]->Value = 2;
iFields->Item["https//schemas.microsoft.com/cdo/configuration/smtpauthenticate"]->Value = _variant_t(1); // Basic
iFields->Item["https//schemas.microsoft.com/cdo/configuration/sendusername"]->Value = _variant_t(szUser);
iFields->Item["https//schemas.microsoft.com/cdo/configuration/sendpassword"]->Value = _variant_t(szPassword);
if(iUseSSLTLS == 2)
iFields->Item["https//schemas.microsoft.com/cdo/configuration/sendtls"]->Value = _variant_t(true);
else
iFields->Item["https//schemas.microsoft.com/cdo/configuration/smtpusessl"]->Value = _variant_t(true);
iFields->Update();
etc... etc...
If I use this code with smtp.gmail.com
:如果我将此代码与smtp.gmail.com
:
I obtain the following response:我得到以下回应:
(sorry ... part of the message is in Italian language, but take a look at the bold/italic one) (对不起......部分消息是意大利语,但请看一下粗体/斜体)
Obviously, if I configure Outlook 2010 using the same parameters, it works perfectly.显然,如果我使用相同的参数配置 Outlook 2010,它就可以完美运行。
One more thing, if I use port 465 and SSL:还有一件事,如果我使用端口 465 和 SSL:
the code works fine, but I need to configure 587 port and TLS.代码工作正常,但我需要配置 587 端口和 TLS。
I eventually tried smtpusessl
and sendtls
together, setting them true:我最终尝试将smtpusessl
和sendtls
放在一起,将它们设置为 true:
iFields->Item["https//schemas.microsoft.com/cdo/configuration/sendtls"]->Value = _variant_t(true);
iFields->Item["https//schemas.microsoft.com/cdo/configuration/smtpusessl"]->Value = _variant_t(true);
And I obtain the following error:我得到以下错误:
After over 2 years, I found a solution, well ... not a solution, but now I know why it didn't work, e why it will never work. 2 年多之后,我找到了一个解决方案,嗯……不是一个解决方案,但现在我知道为什么它不起作用,为什么它永远不会起作用。 It seems there's a bug in CDO library: it can handle STARTTLS command on port 25, but it can't on port 587. CDO 库中似乎存在一个错误:它可以在端口 25 上处理 STARTTLS 命令,但不能在端口 587 上处理。
You can read more here: https://social.technet.microsoft.com/Forums/en-US/37d00342-e5e9-4c8d-975d-44362332d426/bug-in-cdomessage-smtpserverport-587-fails?forum=ITCG您可以在此处阅读更多信息: https : //social.technet.microsoft.com/Forums/en-US/37d00342-e5e9-4c8d-975d-44362332d426/bug-in-cdomessage-smtpserverport-587-fails?forum=ITCG
As I've just written above, it's a bug and I think Microsoft will never correct it.正如我刚刚在上面写的,这是一个错误,我认为微软永远不会纠正它。 The recommendation for the future is to abandon CDO and use "Power shell" or third-party components.未来的建议是放弃 CDO 并使用“Power shell”或第三方组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.