cnbatch
2022-05-25 02:24:18 +08:00
gsoap XML 操控 ews 实在太弯弯绕绕了,而且由于许可证原因( GPLv2+商业授权),我没法在我所在的公司环境内测试。
我用以下代码在公司环境里发送图片附件,试过了没问题。用的是 ews 自己的测试代码+小修改:
//const auto env = ews::test::environment(); //由于我会指定内部 ews 服务器,所以注释掉 env
auto service = ews::service("https:// *********", "", "",""); // 我所在的公司启用了 SSO ,所以不用输入用户名和密码
auto message = ews::message();
auto mail_subject = "Test mail from application";
message.set_subject(mail_subject);
std::vector<ews::mailbox> recipients;
recipients.push_back(ews::mailbox("president@example.com"));
message.set_to_recipients(recipients);
auto text = ews::body("Welcome!\n\nThis is a test.\n");
message.set_body(text);
auto mail_attachment = ews::attachment::from_file(R"(D:\picture.png))"); // 自己指定文件路径
auto mail_id = service.create_item(message, ews::message_disposition::save_only);
service.create_attachment(mail_id, mail_attachment);
auto search_expression = ews::is_equal_to(ews::item_property_path::has_attachments, true);
ews::distinguished_folder_id drafts = ews::standard_folder::drafts;
auto ids = service.find_item(drafts, search_expression);
for (auto &ids : ids)
{
auto msg = service.get_message(ids);
for (auto &reciver : msg.get_to_recipients())
{
std::cout << reciver.value() << "\n"; // 收件人邮箱逐个显示出来
}
if (msg.get_subject() == mail_subject)
{
service.send_item(id);
break;
}
}
先用纯英文字符的内容去试。