如何更改Outlook邮件的发件人

本文关键字:何更改 Outlook | 更新日期: 2023-09-27 18:20:28

我已经成功地通过asp.net应用程序中的c#发送了带有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。我找不到任何更改发件人的内容。是否有人有关于如何更改这些凭据或在哪里查找凭据的更多信息?

如何更改Outlook邮件的发件人

如果您想控制电子邮件,就不能使用OLE。OLE只是控制与运行帐户绑定的本地outlook实例。

您必须改用exchange API。有了它,您可以创建一个约会,如MSDN文章中所述:如何:在Exchange2013中使用EWS创建约会和会议

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上获得。

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

如果您正在构建一个在服务器端上下文中运行的解决方案,则应该尝试使用那些可以安全执行无人参与的组件。或者,您应该尝试找到至少允许部分代码运行客户端的替代方案。如果使用服务器端解决方案中的Office应用程序,则该应用程序将缺乏成功运行所需的许多功能。此外,您将在整体解决方案的稳定性方面承担风险。请参阅"Office服务器端自动化的注意事项"一文中的更多内容。

您可以考虑在Exchange中使用EWS托管API、EWS和web服务。