Jump to content

Recommended Posts

Posted

Deixo aqui um pequeno exemplo de como fazer. Neste caso também será necessário configurar o IIS:

Existem montes de maneiras de o fazer,esta é apenas uma maneira simples =)

using System;
using System.Web;
using System.Web.Mail;

public partial class _xxxx : System.Web.UI.Page
{
   public void enviar_Click(object sender, EventArgs e)
   {
       MailMessage mailMsg = new MailMessage();
       mailMsg.From ="Email para envio";
       mailMsg.To = "email remetente";
       mailMsg.Subject = "assunto";
       mailMsg.Body = "texto de email";
       try
       {
           SmtpMail.SmtpServer = "localhost";
           SmtpMail.Send(mailMsg);
       } 
       catch (System.Exception erro)
       {
           lblResultado.Text = erro.Message;
       }
       finally
       {
            mailMsg = null;
       }
   }
}

IIS configuration:

1.Abrir IIS-- Start->control panel->Administrive Tools->Internet Information Services

2. ir a (local computer) -> Default SMTP Virtual Server, carregar com butao direito e abrirá as propriedades

3. Ir a Access tab e carregar em Relay... button and Relay Restrictions window pops up. meter o pisco "All except the list below" option, e depois carregar em OK

  • 8 years later...
Posted

Deixo aqui um exemplo que funciona perfeitamente em C#:

                        SmtpClient client = new SmtpClient
                        {
                            Port = 587,
                            EnableSsl = true,
                            DeliveryMethod = SmtpDeliveryMethod.Network,
                            UseDefaultCredentials = false,
                            Credentials = new NetworkCredential("email", "password"),
                            Host = "smtp.gmail.com"
                        };
                        using (MailMessage mm = new MailMessage())
                        {
                            mm.From = new MailAddress("email", "nome");
                            mm.To.Add(_ldapFunctions.GetEmail(textBox1.Text));
                            mm.Subject = "Assunto";
                            mm.Body = "Corpo da mensagem";
                            mm.BodyEncoding = Encoding.UTF8;
                            mm.IsBodyHtml = true;
                            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                            client.Send(mm);
                        }

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.