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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BlueYonderCommented:
try adding
client.TargetName = "STARTTLS/smtp.office365.com";
0
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.