简体   繁体   English

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

[英]How do you change the sender of Outlook messages?

I've been successfully sending out appointment invites with outlook through c# in an asp.net application. 我已经成功地通过asp.net应用程序中的c#发送了带有Outlook的约会邀请。 I'm using the following code: 我正在使用以下代码:

//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();
}

This works, but my problem is that it's sending them from my email which I'm logged into with outlook on the same computer. 这可行,但是我的问题是它是从我用同一台计算机上的Outlook登录的电子邮件中发送邮件。 I'd like to send them from a different email, so that they appear more like system notifications coming from my application rather than a personal email. 我想从其他电子邮件中发送它们,以便它们看起来更像是来自我的应用程序的系统通知,而不是个人电子邮件。 I do have the username and password for the account, but the application is eventually going to be run on a remote server, so I can't just log into outlook with another email. 我确实有该帐户的用户名和密码,但是该应用程序最终将在远程服务器上运行,因此我不能仅通过另一封电子邮件登录Outlook。 Nothing I've been able to find changes the sender. 我无法找到发件人的任何更改。 Does anyone have any more information on how to change these credentials, or where it looks for the credentials? 是否有人有关于如何更改这些凭据或在何处查找凭据的更多信息?

You can't use OLE if you would like to control the emails. 如果您想控制电子邮件,则不能使用OLE。 OLE is just to control the local outlook instance which is tied to the running account. OLE仅用于控制与运行帐户绑定的本地Outlook实例。

You must use the exchange API instead. 您必须改为使用交换API。 With it you can create an appointment like described in this MSDN article: How to: Create appointments and meetings by using EWS in Exchange 2013 有了它,您可以像本MSDN文章中所述创建约会如何:在Exchange 2013中使用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");

The library is open source and available at github . 该库是开源的,可从github获得

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment. Microsoft当前不建议也不支持任何无人参与的非交互客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT Services)中的Microsoft Office应用程序自动化,因为Office可能表现出不稳定的行为和/在此环境中运行Office时出现死锁或死锁。

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. 如果要构建在服务器端上下文中运行的解决方案,则应尝试使用对无人值守执行安全的组件。 Or, you should try to find alternatives that allow at least part of the code to run client-side. 或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。 If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. 如果您从服务器端解决方案中使用Office应用程序,则该应用程序将缺少许多成功运行所需的功能。 Additionally, you will be taking risks with the stability of your overall solution. 此外,您将承担整体解决方案稳定性的风险。 Read more about that in the Considerations for server-side Automation of Office article. 在《 服务器端Office自动化注意事项》一文中了解有关此内容的更多信息。

You may consider using the EWS Managed API, EWS, and web services in Exchange instead. 您可以考虑在Exchange中使用EWS托管API,EWS和Web服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM