Hello, how am I trying to send emails through a form in asp but it does not work for me and this is what I have behind the code (.cs)
protected void btnform_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add(email.Value);
msg.Body = comentarios.Value;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "[email protected]";
NetworkCred.Password = "mipasswords";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587 ;
smtp.EnableSsl = true ;
try
{
smtp.Send(msg);
}
catch (Exception ec)
{
}
}
This is my code on the front but I do not know which part does not work XP, oh and by the way I have another question, if I have my host service as I do to send emails from my domain / host or as it says XD
<div class="seven_col_to_one_col">
<form action="/contacto.aspx" method="post" runat="server" id="test">
<input runat="server" required name="nombre" type="text" class="form" id="nombre" placeholder="nombre"/>
<input runat="server" required pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" name="email" type="email" class="form" id="email" placeholder="e-mail"/>
<input runat="server" type="text" name="comentarios" rows="8" class="form comentarios" id="comentarios" placeholder="comentarios" />
<button runat="server" id="submit" type="submit" class="btn_form" name="submit" value="enviar" onclick="btnform_Click">Enviar</button>
</form>
</div>