Using windows live as SMTP relay server

Today I started writing a program to notify me when IP assigned to my router by my broadband provider changes. I wanted this program to check IP address of the router every few minutes and send me email if it detects that IP is changed. For sending email, I used System.Net.Mail.SmtpClient which requires a smtp host. Instead of running a smtp server on my machine, I started looking for free smtp relay servers available on the internet. I was surprised to find out that there are plenty of them available. In fact most of the popular email service providers like windows live, yahoo, gmail offer smtp relay services. You can read more about smtp relay servers and get a list of freely available smtp relay servers here.

Below is the code I used to send email notification using windows live smtp relay. If you want to use gmail, you can use "smtp.gmail.com" as the smtphost with gmail credentials.

static
bool SendEmailNotification(string newIpAddress)
{
    bool success = false;

    //
    // Send email using live account
    //
    SmtpClient mailClient = new SmtpClient("smtp.live.com", 587);
    mailClient.UseDefaultCredentials = false;
    mailClient.EnableSsl = true;

    MailMessage message = new MailMessage("WindowsLiveUserName@live.com", destination@domain);
    message.Subject = "Require immediate action – IP address change";
    message.Body = "New IP address is " + newIpAddress;
    message.Priority = MailPriority.High;

    NetworkCredential credentials =
       
new NetworkCredential("WindowsLiveUserName@live.com", "YourPassword", "");
    mailClient.Credentials = credentials;

    try
    {
        mailClient.Send(message);
        success = true;
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
    }

    return success;
} 

 

I am still making some changes to my IpChangeMailer program. I will make it available for download once it is complete.

Thanks.
Kanwal

3 thoughts on “Using windows live as SMTP relay server

  1. Hi,
    I dont understand. Basically the IP that you get from your provider stays unless you do not disconnect or switch off your router, right? 
    So, I am not sure if the ISP can change the IP of a client in this way, even if it does, don't you get disconnected ?
    Please clarify me if I am wrong. 
    And by the way I got your site address from the contacts mentioned in the `Making PHP faster on IIS` webcast.
     
    Pradeep.

  2. Hi,
    I'm trying to send a email with this in C# but it does not work.
    Anybody can tell me what is wrong?
    Thanks
    (it is only a test)
                    MailMessage mailMessage = new MailMessage("bernybon@hotmail.com", "bernybon@hotmail.com");
                    mailMessage.Subject = "Your BabyfootClub username and password.";
                    mailMessage.Body = "Your username is: " + sUsername + "\r\n";
                    mailMessage.Body += "Your password is: " + sPasswrod + "\r\n";

                    SmtpClient smtpClient = new SmtpClient("smtp.live.com", 25); // the port used by smtl.live.com is 25 not 587
                    smtpClient.EnableSsl = true;
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials = new System.Net.NetworkCredential("bernybon@hotmail.com", "mypassword", "www.hotmail.com");
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
               
                    smtpClient.Send(mailMessage);

Leave a Reply

Your email address will not be published. Required fields are marked *