我们使用Outlook中的备用帐户发送电子邮件。当我使用Outlook Object Model进行此操作时,一切都很好,但是当我们使用Redemption(5.10.0.4312)进行操作且Outlook的默认(!)帐户是不使用Exchange缓存模式时,该电子邮件实际上是使用默认帐户发送的。 另一个帐户(other@adomain.de)是否使用缓存模式似乎无关紧要。
private static void CreateAndSendMailItemWithRedemption()
{
Redemption.RDOSession session = Activator.CreateInstance(
Type.GetTypeFromProgID("Redemption.RDOSession")) as RDOSession;
session.Logon();
var targetFolder =
session.GetDefaultFolder(rdoDefaultFolders.olFolderDrafts) as RDOFolder2;
string recipientAddress = "some@recipient.de";
string accountNameForSending = "other@adomain.de";
var mailItem = targetFolder.Items.Add();
mailItem.To = recipientAddress;
mailItem.Subject = "Automated mail from Redemption";
var accounts = session.Accounts.Cast<RDOAccount>().ToList();
Console.WriteLine(
"Accounts in Outlook: " + string.Join(",", accounts.Select(_ => _.Name)));
var account =
accounts
.FirstOrDefault(
_ => _.Name.Equals(
accountNameForSending,
StringComparison.CurrentCultureIgnoreCase));
mailItem.Account = account ?? throw new NullReferenceException(nameof(account));
const string defaultStr = "default";
mailItem.Body = $"Sent from {mailItem.Account?.Name ?? defaultStr} account.";
mailItem.Send();
mailItem = null;
targetFolder = null;
session = null;
}
这里的陷阱是发件人看不到出了什么问题;如果他们保存了该电子邮件,则尽管使用默认帐户发送了该电子邮件,但该电子邮件仍很好地标记了备用帐户。