Solved

SMTP email from ASP.NET website

Posted on 2010-09-02
5
285 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Trouble with References... 5 44
Binding a check box in an Asp.net DataGrid 4 39
Please explain "Multi-Tenant Services" 5 63
Split in Javascript 5 31
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

22 Experts available now in Live!

Get 1:1 Help Now