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

时间:2015-11-03 17:32:25

标签: c# asp.net email outlook

我已成功通过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。我没有找到任何改变发件人的东西。有没有人有关于如何更改这些凭据或在哪里查找凭据的更多信息?

2 个答案:

答案 0 :(得分: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获得。

答案 1 :(得分: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