Skip to main content
gamedev.net
🔒 Locked

[.net] SMTPClient Send Problem

Started by coolblue Oct 17, 2006 at 3:05 AM 9 replies 1.8k views
Original Post
coolblue
coolblue
I am attempting to send mail from a site on my home computer (windows xp pro). I have SMTP set up and the firewall has port 25 open. If I run the following code on a .net1.1 site it works. ------------------------------------------------------------------------------------------------- MailMessage mail=new MailMessage(); mail.To=sendtoemail; mail.From=fromemail; mail.Body=strBody; mail.Subject="Registration Confirmation"; SmtpMail.SmtpServer="127.0.0.1"; try { SmtpMail.Send(mail); } catch(Exception ex) { string errex=ex.Message; } -------------------------------------------------------------------------------------------------- But if I run the same code on a 2.0 site it does not work. Also if I use the Suggested SMTPClient code below, it also does not work. I get no errors but the mail never arrives at my inbox. --------------------------------------------------------------------------------------------------- MailMessage mail = new MailMessage(); mail.To.Add(sendtoemail); MailAddress address = new MailAddress(fromemail); mail.From = address; mail.Body = "This is a test Mail"; mail.Subject = "test mail"; try { SmtpClient snd = new SmtpClient(); snd.Host = "127.0.0.1"; snd.Send(mail); } catch (Exception ex) { string errex = ex.Message; } --------------------------------------------------------------------------------------------------- Any ideas on why the 1.1 version works but the 2.0 does not?
zangetsu
zangetsu
If your not getting any errors when the code runs, but the message isn't delivered either, then Its possible that the mail service is eating the message. Turn on and/or check the mail server's logs. If nothing else this will allow you to verify that your app and the server are communicating; one less possible point of failure to eliminate.
coolblue
coolblue
The log appears to suggest that the hotmail address I am sending to is not receiving any data.
zangetsu
zangetsu
So then I am to understand that you are using a mail server as a relay just to test with then? And that when the message is forward on to the hotmail servers, the message just dissappears? Sounds like spam protection is your problem.

If you can, try having your app connect to your ISP's outgoing mail server. Although this can be a bit more tricky if the have auth requirements.
coolblue
coolblue
I have found that it will send to my other email at blueyonder.co.uk. It is just the hotmail one that it will not send to. It is strange that I can send to the hotmail address from .net 1.1 though.
BradSnobar
BradSnobar
The dns class resolves hosts a bit differently in 1.1 and 2.0. (It is used inside the smtp client)

This might be causing problems with your loopback.

You might try using "localhost" instead of 127.0.0.1

Hopefully, that will resolve better inside the smtp client.
coolblue
coolblue
Ok this is really getting annoying!!!!!!!!!!

I have now moved my site up to a host server and it is still not sending to hotmail!

I have changed the host to localhost but still no luck. I thought this was a problem with my home pc's smtp server setup but now it is on the host server I presume it is a bug in .net! Every other address I send to is fine it is just hotmail accounts.

How can microsoft .net not be able to send to microsoft hotmail?

BradSnobar
BradSnobar
Does the host have a name or other IP address that can be used instead.

ie.) 10.12.3.2 or whatever.
You can Query the machine for the IP address of that machine and use that. Look at the DNS class.
coolblue
coolblue
Quote:
Original post by BradSnobar
Does the host have a name or other IP address that can be used instead.

ie.) 10.12.3.2 or whatever.
You can Query the machine for the IP address of that machine and use that. Look at the DNS class.


Why would this only prevent hotmail receiving the mail? It gets sent properly but hotmail accounts do not receive the mail at all (ie it is not getting tagged as spam). Yahoo receives the mails perfectly fine as do my pop3 accounts and my work account.

Evil Steve
Evil Steve
This may be related - I had some similar problems when I wrote a SMTP mail sender in C++. Hotmail's mail server IP isn't the same as it's web server IP.
When you do a DNS lookup normally, you're doing a A record lookup, which returns the IP of the Hotmail web server. You need to do an MX lookup to get the IP of the mail server.

What's probably happening is you're trying to send mail to Hotmail's web server IP rather than the SMTP server IP.
coolblue
coolblue
Quote:
Original post by Evil Steve
This may be related - I had some similar problems when I wrote a SMTP mail sender in C++. Hotmail's mail server IP isn't the same as it's web server IP.
When you do a DNS lookup normally, you're doing a A record lookup, which returns the IP of the Hotmail web server. You need to do an MX lookup to get the IP of the mail server.

What's probably happening is you're trying to send mail to Hotmail's web server IP rather than the SMTP server IP.


I am sending to a hotmail address eg name@hotmail.com, I do not use any ips apart from my smtpserver.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.