【问题标题】:How do you change the sender of Outlook messages?如何更改 Outlook 邮件的发件人?
【发布时间】:2018-03-02 21:59:15
【问题描述】:

我已经通过 c# 在 asp.net 应用程序中成功发送了带有 Outlook 的约会邀请。我正在使用以下代码:

//send out the outlook notification
Outlook.Application outlookApp = new Outlook.Application();
Outlook.AppointmentItem newMeeting = outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem;

if (newMeeting != null)
{
    newMeeting.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
    newMeeting.Location = "TBD";
    newMeeting.Subject = "New SEB Consult";
    newMeeting.Body = "A new meeting has been scheduled. If you're a member of the team, please accept";
    newMeeting.Start = meetingDate;
    newMeeting.Duration = 60;
    Outlook.Recipient recipient = newMeeting.Recipients.Add("Smith John");
    recipient.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
    ((Outlook._AppointmentItem)newMeeting).Send();
}

这可行,但我的问题是它是从我在同一台计算机上使用 Outlook 登录的电子邮件发送的。我想从不同的电子邮件发送它们,这样它们看起来更像是来自我的应用程序的系统通知,而不是个人电子邮件。我确实有该帐户的用户名和密码,但该应用程序最终将在远程服务器上运行,因此我不能只使用另一封电子邮件登录 Outlook。我找不到任何改变发件人的东西。有没有人有更多关于如何更改这些凭据或在哪里查找凭据的信息?

【问题讨论】:

标签: c# asp.net email outlook


【解决方案1】:

如果您想控制电子邮件,则不能使用 OLE。 OLE只是控制本地outlook实例绑定到流水账。

您必须改为使用交换 API。有了它,您可以创建一个约会,如这篇 MSDN 文章中所述:How to: Create appointments and meetings by using EWS in Exchange 2013

Appointment appointment = new Appointment(service);

// Set the properties on the appointment object to create the appointment.
appointment.Subject = "Tennis lesson";
appointment.Body = "Focus on backhand this week.";
appointment.Start = DateTime.Now.AddDays(2);
appointment.End = appointment.Start.AddHours(1);
appointment.Location = "Tennis club";
appointment.ReminderDueBy = DateTime.Now;

// Save the appointment to your calendar.
appointment.Save(SendInvitationsMode.SendToNone);

// Verify that the appointment was created by using the appointment's item ID.
Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));
Console.WriteLine("\nAppointment created: " + item.Subject + "\n");

该库是开源的,可通过github 获取。

【讨论】:

  • 嗨,抱歉耽搁了,但我现在才有时间回到这个问题。因此,如果我理解正确,约会不是 Outlook 独有的,所以我可以使用这个开源 api 来创建与 Outlook 兼容的约会?
【解决方案2】:

Microsoft 目前不推荐也不支持从任何无人值守的非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)自动化 Microsoft Office 应用程序,因为 Office在此环境中运行 Office 时可能会出现不稳定的行为和/或死锁。

如果您要构建在服务器端上下文中运行的解决方案,您应该尝试使用已确保无人值守执行安全的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方案。如果您使用服务器端解决方案中的 Office 应用程序,该应用程序将缺少许多成功运行所需的功能。此外,您将承担整体解决方案稳定性的风险。在Considerations for server-side Automation of Office 文章中阅读更多相关信息。

您可以考虑改用EWS Managed API, EWS, and web services in Exchange。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多