Zaloguj | Zarejestruj | FAQ
Anonymous

HTML e Asp.net

+ Odpowiedz

Posty: 2 Strona 1 z 1


HTML e Asp.net

przez rhribeiro13 » Wt paź 28, 2014 1:02 pm

Estou tentando enviar um e-mail pelo visual studio. Alguém poderia me ajudar. Segue os dois códigos.


AbrirChamado.aspx (código HTML)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AbrirChamado.aspx.cs" Inherits="Chamado.AbrirChamado" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>

<form runat="server" method="post">
<fieldset id="usuario"><legend>Identificação do Usuário</legend>
<p>Nome: <input type="text" name="tNome" id="cNome" size="20"/></p>
<p><label for="email">Email:</label>
<input type="text" id="email" name="tEmail" size="40"/></p>
</fieldset>

<fieldset id="mensagem"><legend>Mengsaem do Usuário</legend>
<p><label for="cMsg">Mensagem:</label></p>
<textarea name="tMsg" id="cMsg" cols="45" rows="5"></textarea>
</fieldset>

<input type = "submit" name="BTEnvia" value="Enviar"/>
</form>

</body>
</html>

AbrirChamado.aspx.cs (código aps.net)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Text;

namespace Chamado
{
public partial class AbrirChamado : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BTEnvia(object sender, EventArgs e)
{
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587 /*TLS*/);
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("usuário email", "senha");

MailMessage msg = new MailMessage();
msg.From = new MailAddress("crcservicedesk@gmail.com");
msg.To.Add(new MailAddress("rhribeiro13@gmail.com"));
msg.Priority = MailPriority.Normal;
msg.Body = "Teste";
msg.IsBodyHtml = true;

try
{
smtp.Send(msg);
}
catch (Exception ex)
{
}

}
}
Avatar użytkownika

rhribeiro13

  • Posty: 1
  • Dołączył(a): Wt paź 28, 2014 12:58 pm

Re: HTML e Asp.net

przez XainPro » So lis 01, 2014 12:54 pm

protected void Page_Load(object sender, EventArgs e)
{
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("your.own@mail-address.com");
mailMessage.From = new MailAddress("another@mail-address.com");
mailMessage.Subject = "ASP.NET e-mail test";
mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
SmtpClient smtpClient = new SmtpClient("smtp.your-isp.com");
smtpClient.Send(mailMessage);
Response.Write("E-mail sent!");
}
catch(Exception ex)
{
Response.Write("Could not send the e-mail - error: " + ex.Message);
}
}
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm


+ Odpowiedz

Strona 1 z 1