1

I am sending mail with:

var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
    var emailp = new EmailProperties();
    emailp.BCC = new List<string>{"a@mail.com"};
    emailp.To = new List<string>{"b@mail.com"};
    emailp.From = "from@mail.com";
    emailp.Body = "<b>html</b>";
    emailp.Subject = "subject";
    Utility.SendEmail(_clientContext, emailp);
    _clientContext.ExecuteQuery();
}

The mail is sent but the from address is ignored and my servers from address is used. Can I use a from address with Utility.SendEmail? When I convert my code to use the .NET framework SMTP class the from address is respected.

Update

When I set my servers from email address in the outgoing email settings in central admin to empty I get the exception: The parameter 'address' cannot be an empty string. Parameter name: address. This happens even when I set emailp.From = "from@mail.com"

0

Try to set emailp.From as below

emailp.From = new string[] { "from@mail.com" };

I think if the email is not correct or not set properly it by default use the email that already set at From Adress in the Outgoing Email Settings in the Central Administration

enter image description here

  • emailp.From is of type string. So this line: emailp.From = new string[] { "from@mail.com" }; Gives a build error. – Danny Nov 24 '18 at 10:33
  • And when I set the outgoing email settings from address to empty I get the exception: The parameter 'address' cannot be an empty string. Parameter name: address. This happens even when I set emailp.From = "from@mail.com"; – Danny Nov 24 '18 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.