Lunarpages Web Hosting Forum

Author Topic: Send e-mail from ASP.NET  (Read 2615 times)

Offline mps

  • Space Explorer
  • ***
  • Posts: 8
Send e-mail from ASP.NET
« on: August 31, 2007, 09:37:39 AM »
Hi, has anyone figured out how to do this? Here's the code I'm using:


        MailMessage msg = new MailMessage("admin@mydomain.com", "recipient@nowhere.com", "Testing", "Testing 123");
        SmtpClient mail = new SmtpClient("mail.mydomain.com", 25);
        System.Net.NetworkCredential cred = new System.Net.NetworkCredential("admin@mydomain.com", "secret");

        mail.UseDefaultCredentials = false;
        mail.Credentials = cred;

        try {
            mail.Send(msg);
            Response.Write("OK");
        } catch (Exception ex) {
            Response.Write(ex.ToString());
        }


I keep getting this error response:

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated

Any ideas? Thanks.

Offline VideoGuy

  • Spacescooter Operator
  • *****
  • Posts: 45
Re: Send e-mail from ASP.NET
« Reply #1 on: September 03, 2007, 08:35:20 AM »
Maybe there is something in this post that will help.

Offline mps

  • Space Explorer
  • ***
  • Posts: 8
Re: Send e-mail from ASP.NET
« Reply #2 on: September 04, 2007, 10:56:08 AM »
Hi VideoGuy, I saw that post, but it didn't really help. I did, however, just figure it out. Here goes:

When you test on your local machine, you do need to authenticate, and you need to set the host name to mail.yourdomain.com. On my machine, I test with the ASP.NET 2.0 development Web server, and I have SMTP services running.

Then when you publish to your site, you DO NOT authenticate, and you also change the host name to localhost.

Gee, if only someone at LP made this information available. I hope this post saves others the hours of trial and error (and frustration) that I endured.

Cheers.

Offline xiirus

  • Newbie
  • *
  • Posts: 1
Re: Send e-mail from ASP.NET
« Reply #3 on: September 30, 2007, 08:07:36 PM »
I had this code a few days ago and it worked:


Code: [Select]
MailMessage message = new MailMessage();
message.From = new MailAddress("test@mydomain.com");
message.To.Add(new MailAddress("to@gmail.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient("localhost", 25);
client.Send(message);

but now it just doesn't work. Can anyone from Lunarpages clear this up?

I get an error with "This mail server requires authentication when attempting to send to a non-local e-mail address."

Offline joytony

  • Trekkie
  • **
  • Posts: 11
Re: Send e-mail from ASP.NET
« Reply #4 on: October 06, 2007, 05:52:52 AM »
Any lp support guy answer this?

I send a request 5 months ago, still haven't get a good result. :?