Asp.Net/C# WebPage not sending emails.

Hi,
we develop using Visual Studio 2013.
A client has requested us to develop a webpage that has to send emails from our network to ouside clients. We have not been able to send emails yet. We think the issue is that our client uses Office365 in the cloud for their email accounts.

Our code is the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;

namespace SGTagler.Controller
{
    public class envio_email
    {
        /* Cliente SMTP
         * Gmail:  smtp.gmail.com  puerto:587
         * Hotmail: smtp.live.com  puerto:25
         */

        SmtpClient server = new SmtpClient("smtp.office365.com", 587);

        public envio_email()
        {
            /* Autenticacion en el Servidor
             * Utilizaremos nuestra cuenta de correo
             *
             * Direccion de Correo (Gmail o Hotmail)
             * y Contrasena correspondiente
             */

            server.Credentials = new System.Net.NetworkCredential("asesoriainformatica1@tagler.cl", "1xxxx4"); 
  

            //Habilitar o deshabilitar conexion segura
            server.EnableSsl = true;
        }
 
        public void MandarCorreo(MailMessage mensaje)
        {
            server.Send(mensaje);
        }

    }

}

Open in new window

LVL 2
José PerezAsked:
Who is Participating?
 
Miguel OzSoftware EngineerCommented:
Oscar:
There are two properties (UseDefaultCredentials and DeliveryMethod ) that requires a value in your constructor , the new constructor should be:
public envio_email()
{
	/* Autenticacion en el Servidor
	 * Utilizaremos nuestra cuenta de correo
	 *
	 * Direccion de Correo (Gmail o Hotmail)
	 * y Contrasena correspondiente
	 */

	server.Credentials = new System.Net.NetworkCredential("asesoriainformatica1@tagler.cl", "1xxxx4"); 
	//Use Credentials property when connecting to the server
    smtpClient.UseDefaultCredentials = false;
	//Email is sent through the network to an SMTP server.
    client.DeliveryMethod = SmtpDeliveryMethod.Network; 	
	//Habilitar o deshabilitar conexion segura
	server.EnableSsl = true;
}

Open in new window

Notes:  1)I assume that credentials and server location are correct. SMTP server address is found at My Account" under "Settings for POP, IMAP, and SMTP access".
2) If more help needed please post error details including stack trace.
0
 
BlueYonderCommented:
try adding
client.TargetName = "STARTTLS/smtp.office365.com";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.