• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

SMTP email from ASP.NET website

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
dianas70
Asked:
dianas70
  • 3
  • 2
1 Solution
 
CmdoProg2Commented:
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
 
dianas70Author Commented:
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
 
CmdoProg2Commented:
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
 
dianas70Author Commented:
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
 
dianas70Author Commented:
I finally got the code to work.  Thanks so much!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now