In between the head and body I have :
<script language="C#" runat="server">
private void sendmail(Object sender, EventArgs e)
{
try
{
MailMessage mailObj = new MailMessage();
mailObj.From = "no-reply@domain.be";
mailObj.To = "nick@domain.be";
mailObj.Subject = "Email via site ";
mailObj.Body = "Dit is een email verstuurd via ASP.net .";
//mailObj.BodyFormat = MailFormat.Text;
SmtpMail.SmtpServer = "smtp.one.com";
SmtpMail.Send(mailObj);
Response.Write("Email werd succesvol vestuurd");
}
catch (Exception x)
{
Response.Write("Email werd niet verstuurd: " + x.Message);
}
}
</script>
and in my body I have
<form id="Form1" method="post" runat="server">
But no email is being send, why not ??
Because you need to trigger the sendmail method. There’s nothing in your code that calls it.
You could have a button on your markup that invokes
sendEmailwhen it is clicked.For example:
Also, SmtpMail is obsolete. Use SmtpClient