Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SMTP email from ASP.NET website

Posted on 2010-09-02
5
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 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