3

The following function works perfectly:

    protected void SendWebMailMessage(string DisplayName, string From, string ReplyTo,
        string To, string Subject, string Body, string Attachments)
    {
        System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver",
             "smtpout.secureserver.net");
        msg.Fields.Add(
             "http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
        msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 
             2);
        msg.Fields.Add(
             "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
        msg.Fields.Add(
             "http://schemas.microsoft.com/cdo/configuration/sendusername", From);
        msg.Fields.Add(
             "http://schemas.microsoft.com/cdo/configuration/sendpassword",
             mailpassword);
        msg.To = To;
        msg.From = DisplayName + "<" + From + ">";
        msg.BodyFormat = MailFormat.Html;
        msg.Subject = Subject;
        msg.Body = Body;
        msg.Headers.Add("Reply-To", ReplyTo);
        SmtpMail.SmtpServer = "smtpout.secureserver.net";
        SmtpMail.Send(msg);
    }

However, I get a build warning telling me that System.Web.Mail is obsolete, and that I should be using System.Net.Mail. So I used System.Net.Mail, and I came up with the following function to replace my old one:

    protected void SendNetMailMessage(string DisplayName, string From, string ReplyTo, 
        string To, string Subject, string Body, string Attachments)
    {
        MailAddress addrfrom = new MailAddress(From, DisplayName);
        MailAddress addrto = new MailAddress(To);
        MailAddress replytoaddr = new MailAddress(ReplyTo);
        System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
        msg.From = addrfrom;
        msg.To.Add(addrto);
        msg.ReplyTo = replytoaddr;
        msg.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient("smtpout.secureserver.net");
        smtp.Credentials = new NetworkCredential(From, mailpassword);
        smtp.Send(msg);
    }

I don't get any exceptions or errors, but my message never goes through. Can anyone tell me what I might be doing wrong? Thanks in advance.

Tom V
  • 125
  • 5
  • 11
  • Are you sure it's authenticating correctly? Better check the event log on the mail server and also on the local system? – RobS Mar 11 '09 at 00:11
  • I don't have access to the mail server logs. It is a hosted mail server. If it weren't authenticating correctly, though, I'd expect the System.Net.Mail.smptClient.Send() method to throw an exception, like System.Web.Mail.SmtpMail.Send() throws an exception when authentication is not successful. – Tom V Mar 11 '09 at 00:26
  • I'm testing a similar implementation (I've just converted to System.Net.Mail too) will see if I get the same problem – RobS Mar 11 '09 at 01:12

2 Answers2

1

I tested you code above an it works fine. I had to add the body and subject properties, but even without them I still received a blank email. I also tried with and without providing credentials, both worked.

Initially I hadn't changed your host string and did receive an exception with the message "Failure sending mail."

bstoney
  • 6,594
  • 5
  • 44
  • 51
1

If I'm not wrong... you are using the Goddady hosting. I'm also using it... and I have **relay-hosting.secureserver.net** as the SMTP server. I don't know... may be can be something like that... or you have not set the Relay in your console.

Romias
  • 13,783
  • 7
  • 56
  • 85