views:

1186

answers:

6

Related:

Send Email via C# through Google Apps account

My question is the same so I implemented Koistya's solution as follows. The heartbreak is that it works beautifully on my dev laptop but when ported to web server it times out with no explanation.

My SMTP config is in my web.config file. I made mods based on Koistya's answer:

<mailSettings>
    **Changed**
      <smtp from="[email protected]">
        <network host="smtp.gmail.com" password="[password]" port="587" 
          userName="[email protected]"/>
      </smtp>
    **Original**
      <!--<smtp from="[email protected]">
        <network host="mail.domain.com" password="[password]" port="25"
          userName="[email protected]"/>
      </smtp>-->
</mailSettings>

My .Net C# code (before & after removed):

  SmtpClient mSmtpClient = new SmtpClient();
  mSmtpClient.EnableSsl = true;
  mSmtpClient.Send(message);

As I said this works great on my dev environment but not on web. Can anyone help? Thanks.

A: 

Could be that the smtp client is not able to access the smtp server (might be disabled by the web host).

Ask the web host if they have a specific smtp server you should be using to send emails with.

Mauro
I appreciate the suggestion but am barely understanding the issue myself. If our domain's email is all going to Google what role would our web host's smtp server play? It seems to me its no longer involved. Kioysta's solution was to point to smtp.gmail.com. ???
I should add that the c# generated-email was working just FINE til we did the switchover to Google apps.
I just read an answer by Josh Kelley to a similar question and realize there is so much about this that I am in the dark on. He says "MX records only affect receiving mail. You can set up a sendmail host to send mail without it having any effect at all on your MX records or your receiving mail." When I switched our company's email over to Google apps, I followed their directions EXACTLY. That's all I know. I don't have a CLUE how to do anythying else in the DNS thing nor how to set up an SMTP server. If anyoneone wants to help me with this, I'll show you exactly what's in our DNS settings
A: 

If your webhost doesn't allow you to send outgoing SMTP mail from their servers, that would cause this problem. For example, GoDaddy only allows you to send outgoing mail through smtpout.secureserver.net from your server, so any attempt to send mail through another host (in this case, smtp.gmail.com) would fail. If your ISP does not block outgoing SMTP (like Qwest does not, for example), then that's why this would work locally.

Check the FAQ with your webhost to see what they have to say about it. Most hosting companies do allow outgoing SMTP, but limit it to a certain number of relays/day, to prevent accidental exploitation for spam forwarding.

You're correct that the MX record on your domain only affects incoming mail. When somebody tries to send mail to [email protected], they hand it to an SMTP server (most likely, the one their ISP gives them), and then SMTP server looks up your MX record to see who handles your email. It will resolve to smtp.gmail.com, so that's who will get your mail, and you get it from them. When you send outgoing mail, it can go through anybody, since you only care about the MX record for the destination domain (where the mail will eventually end up).

Does that make sense? If you'd like some clarification, I can find some tutorials and other explanations to help make sense of it.

rwmnau
Can I get an explanation for the downvote?
rwmnau
+2  A: 

Your settings are correct. We use gmail for sending mail all the time in our web apps. Your server is probably blocking outgoing traffic on port 587. I would contact your host and see if they can help otherwise you will need new mail or a new host.

Chris Mullins
A: 

Failing a response from your hosting company and if you have another server you could send test requests to, try requesting connections to other ports and see what happens.

Adrian Lynch
+1  A: 

Thanks to everyone's help on this site as well as the Google apps forum (although I like this one better) I finally put together all the pieces of the puzzle. For whatever reason port 465 and port 587 would not work. This is what worked for me:

Web.config:

  <smtp from="[email protected]">
    <network host="smtp.gmail.com" password="[password]" port="25" 
      userName="[email protected]"/>
  </smtp>

from the aspx.cs file:

SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.EnableSsl = true;

Thanks again!

+1  A: 

I had the same problem for my form.My website is running on a plesk control panel.All i did was to login to my panel and disable email hosting on my web server. After that my form started sending to a Google apps account.Try out what i did,i am sure u will get a difference.

Kawama... God Bless You

kawama Mugabiii Dennis