Solved

SMTP email from ASP.NET website

Posted on 2010-09-02
5
284 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I finally got the code to work.  Thanks so much!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now