Smtp Problem with 1and1 and asp.net 2.0

I have spent a few days trying to figure out why I cannot send email, using asp.net 2.0, using 1and1 as host. The email would send locally but when I posted the code on a website it would not work. I would get back an error message containing:


'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0,
 Culture=neutral, PublicKeyToken=b77a5c533934e089' failed

I tried port numbers 25, 465, and 587.
Nearly everyone said to use smtp.1and1.com as the mail server but that turned out to be the problem…use mrelay.perfora.net instead. Here is the final code:


SmtpClient theClient = new SmtpClient();
theClient.Host = "mrelay.perfora.net";
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential cred = 
  new System.Net.NetworkCredential("myemailaddr", "mypassword");
theClient.Credentials = cred;
theClient.Port = 25;
theClient.EnableSsl = false;
theClient.Send(mail);

Now the interesting part was I posted the code and it worked fine until one day I received an error message containing ‘…mailbox unrecognized…’. This was a tough one to track down. It turns out I was sending terse message content with the From address as test@test.com. 1and1 construed this to be spam and rejected it. Once I put in “real” data the contact us form worked as expected.

Here is the web site:

Let’s Do Vegas! Contact Form

Doug

Leave a Reply

You must be logged in to post a comment.