Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Last active May 1, 2016 08:27
Show Gist options
  • Save netsi1964/62862fa98161db8e0c3f088a5ddd740a to your computer and use it in GitHub Desktop.
Save netsi1964/62862fa98161db8e0c3f088a5ddd740a to your computer and use it in GitHub Desktop.
Basic send e-mail using ASP.net and C# from an Unoeuro account

Basic send e-mail using ASP.net and C# from an Unoeuro account

If you have an ASP.NET based UnoEuro account, these two files sendEmail.aspx and web.config can be the basic for a simple send e-mail pags.

Setting up to your needs

  • Change all the relevant custom properties found in the two files
  • Customize the content of the send e-mail, and onscreen responses
  • Change the URL of the sendEmail.aspx to fit your need
  • Upload to your unoeuro website using FTP

Remember

There has been no security included in this basic gist. You should implement some kind of security. Comments are welcome!

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net.Mime" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.ComponentModel" %>
<script runat="server" LANGUAGE="C#">
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Net.Mail.MailMessage mailMessage = new System.Net.Mail.MailMessage();
mailMessage.To.Add("[email protected]");
mailMessage.From = new System.Net.Mail.MailAddress("[email protected]");
mailMessage.Subject = "From an UnoEuro account";
mailMessage.Body = "Basic send e-mail using ASP.net and C# from an Unoeuro account";
mailMessage.IsBodyHtml = true;
mailMessage.HeadersEncoding = Encoding.UTF8;
mailMessage.BodyEncoding = Encoding.UTF8;
mailMessage.SubjectEncoding = Encoding.UTF8;
System.Net.Mail.SmtpClient SmtpSender = new System.Net.Mail.SmtpClient();
SmtpSender.Port = 587; //or, whatever port your SMTP server operates on
SmtpSender.Host = "smtp.unoeuro.com";
SmtpSender.Send(mailMessage);
Response.Write("E-mail sent!");
}
catch(Exception ex)
{
Response.Write("Could not send the e-mail - error: " + ex.Message);
}
}
</script>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network host="mail.your.domain" port="587" userName="[email protected]" password="YouShouldBeAbleToFigureThisOneOut" />
</smtp>
</mailSettings>
</system.net>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment