在 VS2008 環境下使用 C++ 撰寫小程式自動發送郵件,尋找合適的介面或類別庫。
#import "cdosys.dll"
using namespace CDO;
_MessagePtr msg = NULL;
msg.CreateInstance(__uuidof(Message));
msg->PutTo("recipient@example.com");
msg->PutFrom("sender@example.com");
msg->PutSubject("Test");
msg->PutTextBody("Body text");
IConfigurationPtr cfg = msg->GetConfiguration();
cfg->Fields->Item["https://schemas.microsoft.com/cdo/configuration/smtpserver"] = "smtp.example.com";
cfg->Fields->Item["https://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
cfg->Fields->Item["https://schemas.microsoft.com/cdo/configuration/sendusing"] = 2; // cdoSendUsingPort
cfg->Fields->Update();
msg->Send();