Click here to Skip to main content
15,887,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everybody,

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

C#
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();



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:

C#
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:

C#
The Credential user has 'Send As' access. maybe need on behalf access or something like that!?
Any idea?
Posted
Updated 21-Oct-16 1:59am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900