Reputation: 355
Could you help me understand why this isn't working? Because I'm unable to create a new MailAddress object using variables in place of the strings that are normally assigned in the Display and Address parameters.
If the following code is used then the email goes through fine from "The Example Sender" (i.e., the Display parameter) whose email address is "[email protected]" (i.e., the Address parameter):
myMessage.From = new MailAddress("[email protected]", "The Example Sender");
However if I want to update the From Address using input that's stored in a variable it no longer works:
myMessage.From = new MailAddress(fromDisplayName, fromEmailAddress);
I'm unable to go in and replace the Display and Address parameters since they're read-only. So I can't do the following:
myMessage.From.DisplayName = fromDisplayName;
myMessage.From.Address = fromEmailAddress;
Any thoughts or suggestions on how I can create a new MailAddresss using variables?
Upvotes: 0
Views: 81
Reputation: 157
The one that does not work has the variables reversed, it should be:
myMessage.From = new MailAddress(fromEmailAddress, fromDisplayName);
Upvotes: 2