EclipseX Posted December 11, 2009 at 04:13 PM Report #299850 Posted December 11, 2009 at 04:13 PM 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
Karbust Posted June 27, 2018 at 12:11 PM Report #611149 Posted June 27, 2018 at 12:11 PM 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); }
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now