Solved

SMTP email from ASP.NET website

Posted on 2010-09-02
5
290 Views
Last Modified: 2012-05-10
I have a site that is supposed to allow me to send emails to registered members of my site.  However I keep getting an error message that says "The "SendUsing" configuration value is invalid."  The developers who created the site can't seem to fix the problem and I think it's because they've been paid already so who cares?

I am savvy enough that I think I can fix the problem if I'm pointed in the right direction.  I found in the web.config file a key called "SMTPServer" but the value is an email address.  I did a search and cannot find in any file where the configuration settings for the SMTP server have been created.  Is that why it isn't working?

I'd be happy to provide any other information that helps get this problem solved.
0
Comment
Question by:dianas70
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 33589940
Check this link

http://www.systemwebmail.com/faq/4.2.2.aspx

If your SMTP Server is on another server, then you will need specify its IP address
                        <network host="127.0.0.1"/>
0
 

Author Comment

by:dianas70
ID: 33591605
I modified the web.config file with the value for the smtp server that was provided to me by the hosting company, instead of the email address that was there.  However, the same error keeps occurring.  I noticed in my other searches for answers that the smtp server key needs to be called or referenced in your code to send the email.

Here's the code from the web.config file:
  <appSettings>

      <add key="MailFromAdmin" value="sales@ourassociation.org"></add>
      <add key="SMTPServer" value="smtpmailer.hostek.net"></add>
   
  </appSettings>

Here's the code from the page sending the email:

        String msgBody;
        MailMessage msg = new MailMessage();

        foreach (DataRow drow in dt.Rows)
        {

            msg.To = drow["Email"].ToString();
            msg.From = ConfigurationManager.AppSettings["MailFromAdmin"].ToString();
            msg.Subject = txtSubject.Text;
            msg.BodyFormat = MailFormat.Html;

            msgBody = "Hi ,";
            msgBody = msgBody + FCKBody.Value.Trim();
            msgBody = msgBody + "<br /> <br />Thanks & Regards <br />Our Team";
            msg.Body = msgBody;

            SmtpMail.Send(msg);

        }

Granted, this isn't everything in the frmMailSend.aspx page, but this is the meat.  Should there be a line of code in the second snippet that refers to the key created in the web.config?

TIA
0
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 500 total points
ID: 33595946
The smtpMail class is obsolete since the release of .Net Framework 2.0 and is only supported in 1.0, 1.1.  SmtpClient is supported by 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0.  However, the missing line is:
SmtpMail.SmtpServer = ConfigurationManager.AppSettings["SMTPServer"].ToString();

or To update the code ... I prefer to set the mailsettings in the web.config ,so the network mail settings can be changed without reprogramming, including port, SSL, credentials, etc.


       //Send the Mail
      System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
      sc.Send(msg);


Place the following in your web.config
	<system.net>
		<mailSettings>
			<smtp from="sales@ourassociation.org">
				<network host="smtpmailer.hostek.net"/>
			</smtp>
		</mailSettings>
	</system.net>

Open in new window

0
 

Author Comment

by:dianas70
ID: 33619546
I have a feeling I did not put something in here correctly now.  I am getting an error

The best overloaded method match for 'System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMessage)' has some invalid arguments

I added the <system.net> code to the web.config file and simply added your two lines

     System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();
     sc.Send(msg);

in my frmMailSend.aspx.cs file as a replacement for the original

    SmtpMail.Send(msg);

was that correct?

0
 

Author Closing Comment

by:dianas70
ID: 33630232
I finally got the code to work.  Thanks so much!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question