O código abaixo é um exemplo simples de como enviar e-mail em ASP.NET com C#.
Salve o código abaixo como email.aspx
<%@ Page language="c#"%>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Web.Mail"%>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
MailMessage mailMsg
= new MailMessage
();
mailMsg.From = "remetente@email.com.br";
mailMsg.To = "destinatario@email.com.br";
mailMsg.Subject = "Assunto";
mailMsg.Body = "Mensagem";
try
{
SmtpMail.SmtpServer = "SMTP.servidor.com.br";
SmtpMail.Send(mailMsg);
lblText.Text = "Email enviado com sucesso!";
}
catch(System.Exception erro)
{
lblText.Text = erro.Message;
}
finally
{
mailMsg = null;
}
}
</script>
<html>
<head>
<title>Email enviado com sucesso!</title>
</head>
<body>
<table border="0" width="100%" height="100%" style="font-family:Verdana;font-size:10px;">
<tr>
<td align="center">
<asp:Label id="lblText" runat="server"/>
</td>
</tr>
</table>
</body>
</html>
Viu! Não tem segredo nenhum.
Apenas importamos o Namespace "System.Web.Mail" para utilizar seus métodos e propriedades referentes à envio de e-mails.
Em breve disponibilizarei um artigo sobre
try,
catch e
finally, ok?!
Aproveitem bem e ateh!