简体   繁体   English

代表其他用户发送电子邮件以获取office365-outlook

[英]Sending email on behalf of other user for office365-outlook

I am sending an email using a console application created using C#.I want to send this email with a different From name , I have found the same code on many sites, but it is not working in my case. 我正在使用使用C#创建的控制台应用程序发送电子邮件。我想使用不同的From name发送该电子邮件,我在许多站点上都找到了相同的代码,但在我的情况下不起作用。

MailAddress mailFrom = new MailAddress("xyz@abc.com", "Sender");

I am using office365- outlook. 我正在使用office365- Outlook。

My complete code is:- 我完整的代码是:

 SmtpClient SmtpServer = new SmtpClient("smtp.office365.com", 25);
            MailAddress mailFrom = new MailAddress("xyz@abc.com", "Mailer");
            MailAddress mailTo = new MailAddress("xyz@abc.com");
            MailMessage mail = new MailMessage(mailFrom, mailTo);

            mailt.Subject = "Test Mail";
            mailt.Body = "This is for testing";

            SmtpServer.Credentials = new System.Net.NetworkCredential("xyz@abc.com", "password");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);

So in this case is it possible to change the sender name for sending email or can we send email on behalf of other user in outlook using code? 因此,在这种情况下,可以更改发送电子邮件的发件人名称,还是我们可以使用代码代表Outlook中的其他用户发送电子邮件?

Using the Outlook object model , you can do: 使用Outlook 对象模型 ,您可以执行以下操作:

Outlook.Application OL = ....;
Outlook._MailItem mail;

mail = OL.CreateItem(Outlook.OlItemType.olMailItem) as Outlook._MailItem;
mail.Subject = subject;
mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mail.HTMLBody = body;

//  add recipients
//  ....

mail.SentOnBehalfOfName = sender;
mail.Send();

This requires Outlook to be installed on your system. 这要求在系统上安装Outlook

To get hints about what could be wrong with your code, you should describe the error messages or failure you are getting. 为了获得有关代码可能出问题的提示,您应该描述错误消息或遇到的故障。

你可以做:

    mail.From = new MailAddress("test@example.com");

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

相关问题 Outlook for Office365 在发送前向用户显示消息 - Outlook for Office365 Display Message to User Before Sending 使用Office 365作为ASP.net中的中继时,如何向电子邮件添加发件人(代表用户) - How to add a sender (on behalf of user) to the email when using Office 365 as relay in ASP.net 无法将电子邮件发送到Office 365 - Trouble Sending Email To Office 365 代表其他用户发送电子邮件 - Sending email on behalf of another user 不允许在Office365上代表我的客户发送电子邮件 - Not allow to send email on behalf of my client on office365 代表用户从守护程序订阅Office 365流通知 - Subscribe from daemon to Office 365 Streaming Notifications on behalf of a user Office 365 REST API - Outlook用户照片 - Office 365 REST API - Outlook User Photo 阅读分配给AD组Outlook 2010 / Office 365的电子邮件地址 - To read the email adress assigned to an AD group Outlook 2010/Office 365 使用设置为代表电子邮件帐户 B 发送的 Office365 电子邮件帐户 A 使用 SendGrid API 发送电子邮件 - Send email with SendGrid API using Office365 email account A which is set to send on behalf of an email account B 如何在使用 Microsoft.Office.Interop.Outlook 从 C# 发送邮件时删除“代表” - How to remove "on behalf of " while sending mail from C# using Microsoft.Office.Interop.Outlook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM