Get from value

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
 
R

Robert Haken [MVP]

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
 
C

Chris Fulstow

Try this:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,298
Latest member
ZenLeafCBDSupplement

Latest Threads

Top