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>{"[email protected]"};
    emailp.To = new List<string>{"[email protected]"};
    emailp.From = "[email protected]";
    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 = "[email protected]"

1 Answer 1

0

Try to set emailp.From as below

emailp.From = new string[] { "[email protected]" };

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

2
  • emailp.From is of type string. So this line: emailp.From = new string[] { "[email protected]" }; Gives a build error.
    – Danny
    Nov 24, 2018 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 = "[email protected]";
    – Danny
    Nov 24, 2018 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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