Iron Speed Technical Forums
Sign up Latest Topics
 
 
 


Reply
  Author   Comment  
krishna

Registered:
Posts: 145
Reply with quote  #1 
Hi
Is there a way end user can configure email settings ?

How can I setup a add page that can take the inputs and 
update the web.config file ?

Or,

How can I read and store the email 'from address' from web.config to a session
variable (on app start) and then use this session var to send emails?

Any guidance is appreciated.
regards
Krishna

Rexxrally

Registered:
Posts: 244
Reply with quote  #2 
In web.config, put this (replace settings as necessary):

<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="RealEmailAddressInYourDomain@yourdomain.com">
        <network host="mail.yourdomain.com" port="25" userName="RealEmailAddressInYourDomain@yourcomain.com" password="youremailpassword" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>
  <appSettings>
    <add key="EmailFromAddress" value="EmailAddressThatYouWantToAppearInTheEmail@whatever.com" />
  </appSettings>
</configuration>

And then in your code, you can do something like this:

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

        private string SendEmail(string subject, string body, ref string strEmailResponse)
        {
            strEmailResponse = "Email Sent Successfully (" + DateTime.Now.ToString("MMMM-dd-yyyy hh:mm") + ")";
            try
            {
                MailMessage msg = new MailMessage();
               string fromEmailAddress = BaseClasses.Configuration.ApplicationSettings.Current.GetAppSetting("EmailFromAddress");
               string toEmailAddress = "youremailrecipient@whateverdomain.com"
                msg.From = new MailAddress(fromEmailAddress);
                msg.To.Add(new MailAddress(toEmailAddress));
                msg.Subject = subject;
                msg.IsBodyHtml = true;
                msg.Body = body;

                SmtpClient smptClient = new SmtpClient();
                smptClient.Credentials = CredentialCache.DefaultNetworkCredentials;

                smptClient.Send(msg);
            }
            catch (Exception ex)
            {
                strEmailResponse = ex.Message;
            }
            return strEmailResponse;
        }



 

Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.

Download Iron Speed Designer

Terms of Service Privacy Statement