如何更改Outlook邮件的发件人?

问题描述 投票:0回答:2

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

//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
2个回答
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获得。


0
投票

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代替。

© www.soinside.com 2019 - 2024. All rights reserved.