使用Exchange 365使用Office 365在C#中发送电子邮件 [英] Sending email in C# using office 365 using exchange API

查看:1120
本文介绍了使用Exchange 365使用Office 365在C#中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我从我的MVC应用程序发送电子邮件时遇到问题。这是代码



Hi Everybody,

I have a problem with sending email from my MVC application. Here is the code

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
              service.UseDefaultCredentials = false;
              service.Credentials = new WebCredentials("EmailSender", "Password");
              string serviceUrl = "https://outlook.office365.com/ews/exchange.asmx";
              service.Url = new Uri(serviceUrl);
              EmailMessage emailMsg = new EmailMessage(service);
              emailMsg.From = currentUser.Email; //This email is different from Credential email
              emailMsg.Subject = mailSubject;
              emailMsg.Body = mailBody;

              emailMsg.SendAndSaveCopy();







问题是凭据帐户与当前用户电子邮件不同。用户不登录域,因此我无法访问其凭据。所以我想使用一个帐户来发送电子邮件而不是用户。当我们使用Exchange服务器时,即使没有凭据也可以发送电子邮件但在办公室365中我收到此错误:






The thing is that the Credential account is different from current user email. The users don't login in the domain so I have no access to their credential. So I want to use an account to send email instead of the users.It was possible to send email even without credential when we were using Exchange server but in office 365 I get this error:

The user account which was used to submit this request does not have the right to send mail on behalf of the specified sending account., Cannot submit message.





我尝试过的方法:





What I have tried:

The Credential user has 'Send As' access. maybe need on behalf access or something like that!?
Any idea?

推荐答案

配置Exchange,以便EmailSender有权代表其他人发送邮件。您需要谷歌如何执行此操作,Exchange配置超出了本网站的范围。
Configure Exchange so that "EmailSender" has the rights to send messages on behalf of other people. You'll need to google how you do that, Exchange config is outside the scope of this site.


这篇关于使用Exchange 365使用Office 365在C#中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆