0

I have newly built a windows 2008 R2 server(with .NET 3.5) and added the following too IIS, SMTP, Visual Web Developer 2010 Express, but no MS Office or Outlook.

and i started SMTP server using IIS 6.0 administration (through control panel -> Admin tools -> IIS 6.0..)

And using the below code...

using System.Net;
using System.Net.Mime;
using System.Net.Mail;

    public static void SendMail(string  From, string To, string Subject, string BodyText)
    {
        MailMessage mailMsg = new MailMessage();
        mailMsg.Subject = Subject;

        //from and To
        mailMsg.From = new MailAddress(From);
        mailMsg.To.Add(new MailAddress(To);

        //Body Text
        mailMsg.Body = BodyText.ToString();

        SmtpClient mSmtpClient = new SmtpClient();
        mSmtpClient.Send(mailMsg);

        // Clean up.
        mailMsg.Dispose();
    }

//Web.Config entry - 255.255.255.255 is the server IP

<system.net>
    <mailSettings>
        <smtp from="myname@gmail.com">
            <network host="255.255.255.255" port="25" userName="" password=""/>
        </smtp>
    </mailSettings>
</system.net>

When i use the above method to send email, it shows an error "Failure Sending Mail Error", but does not give details.

As many people suggested I have also added the IP address to SMTP Server (under properties -> general tab) still shows the same message. So i'm wondering is Outlook required for sending mails from asp.net.

Please suggest what else can i check to find the actual problem and make it work.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
MSBI-Geek
  • 628
  • 10
  • 25
  • No the Net Mail class doesn't depend on Outlook – Steve Feb 21 '14 at 11:42
  • Why are you using `255.255.255.255` as the IP address?! – Lloyd Feb 21 '14 at 11:42
  • _"it shows an error "Failure Sending Mail Error""_ - that's called an exception. Catch it and inspect it, it most likely has an `InnerException` telling you the cause of the issue. @Lloyd he most likely wants to obfuscate the real IP. – CodeCaster Feb 21 '14 at 11:46
  • Missed the GMail part. Duplicate of [How to send email to gmail using SMTPclient in C#?](http://stackoverflow.com/questions/5700115/how-to-send-email-to-gmail-using-smtpclient-in-c) – CodeCaster Feb 21 '14 at 11:53
  • The real IP is different. I will try to look at the inner exception. – MSBI-Geek Feb 21 '14 at 12:03

1 Answers1

0

It would seem you are using the wrong settings, try these with the proper information Username Password Host etc

smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("username", "password");
smtp.Host = "setting";

Hope this helps

Inept Adept
  • 414
  • 4
  • 11