[英]Create new instance of MailAddress using stored variables instead of strings for parameters
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. 因为我无法使用变量代替通常在Display和Address参数中分配的字符串来创建新的MailAddress对象。
If the following code is used then the email goes through fine from "The Example Sender" (ie, the Display parameter) whose email address is "examplesender@mail.com" (ie, the Address parameter): 如果下面的代码用于随后的电子邮件从“示例发件人”经过细(即, 显示参数),其电子邮件地址是“examplesender@mail.com”(即, 地址参数):
myMessage.From = new MailAddress("examplesender@mail.com", "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. 我无法进入并替换Display和Address参数,因为它们是只读的。 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? 关于如何使用变量创建新MailAddress的任何想法或建议?
一个不起作用的变量将其取反,应该是:
myMessage.From = new MailAddress(fromEmailAddress, fromDisplayName);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.