Get from value

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I need to get the "from" value, in my runtime code, which I have in my
web.config:

<system.net>
<mailSettings>
<smtp
deliveryMethod = "network"
from = "(e-mail address removed)">

How can I do this?

Thanks,
Miguel
 
myMailMessage.From = ...

....or you can make child class MyMailMessage : MailMessage and set the From
property in constructor if you need to setit for all e-mails.

There is no other conventional way (except reflection) to set this, because
the From address is set in MailMessage constructor:

string text1 = SmtpClient.MailConfiguration.Smtp.From;
if ((text1 != null) && (text1.Length > 0))
{
this.message.From = new MailAddress(text1);
}

....and the SmtpClient.MailConfiguration property is internal.

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
 
Try this:

SmtpSection section = (SmtpSection)
WebConfigurationManager.GetWebApplicationSection("system.net/mailSettings/smtp");
string emailFrom = section.From;
 
Back
Top