0

Is it possible to use the "from" in the config file as the MailMessage.From when creating an email in .net. Having trouble accessing it. Whenever I try referring ConfigurationManager I get a does not exist error but I am referencing them, see below.

<mailSettings>
  <smtp from="test@test.org" deliveryMethod="Network">
    <network host="smtpsend" defaultCredentials="true"/>
  </smtp>
</mailSettings>

using System.Net.Mail;
using System.Net;
using System.Configuration;
using System.Net.Configuration;

            MailMessage msg = new MailMessage();
            msg.From = ***~~**
            msg.Subject = string.Format(subject);
            msg.IsBodyHtml = true;
            msg.Body = body;
            msg.Priority = MailPriority.Normal;
            msg.To.Add("me");

            SmtpClient client = new SmtpClient();
            client.Send(msg);
Jt2ouan
  • 1,964
  • 9
  • 33
  • 55

1 Answers1

0

Good afternoon have you added an actual reference to the system.configuration dll library? You can check by looking in the references folder of your project in solution explorer. If it is not there, right click your project and choose the add references option. Then click on the .net tab an search for system.configuration. That should take care of your reference issue. Additionally, by specifying the from address in the config file I believe that you do not have to reset it again when actually making a request to send an email.

mreyeros
  • 4,359
  • 20
  • 24
  • 1
    I had the system.configuration reference already but your last sentence helped me with my real question. I don't have to set the msg.to.From as its into the config file. Thanks for the info. I was looking all over for how to grab the From in the smtp but if I just remove the msg.To.From it just defaulls to the one in the mailSettings part of the config file. – Jt2ouan Sep 24 '13 at 19:14