Lounge Network - Knowledge Base

  View Printer Friendly Version Search
KNOWLEDGE BASE HOME » 14. INFORMATION: CORPORATE & BUSINESS HOSTING Viewing Answer
[WINDOWS] Sample ASPX script to send emails
Following is the sample code for sending emails using an ASPX file.

Please create an email.aspx file in your website and put the following contents in it:

<% @Page Language="C#" %>
<% @Import Namespace="System.Net.Mail" %>

<%
String from_email_address = "";
String to_email_address = "";
String smtp_username = "";
String smtp_password = "";
String smtp_server = "";

//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress(from_email_addres);
mail.To.Add(to_email_address);

//set the content
mail.Subject = "This is an email";
mail.Body = "this is a sample body";

//send the message. Replace mail.domain.co.nz with your smtp server.
SmtpClient smtp = new SmtpClient(smtp_server);

// Using authentication to connect to above smtp server to send email.
// Replace txtSMTPUser and txtSMTPPass with your appropriate details.
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(smtp_username, smtp_password);
smtp.UseDefaultCredentials = false;
smtp.Credentials = SMTPUserInfo;
smtp.Send(mail);
%>

Please update the following variables in the script:
from_email_address (The email address which you want to display to the recepient as the sender.)
to_email_address (The email address to whom you want to send the email to.)
smtp_username (The smtp username of the server that you are using to send the email.)
smtp_password (The smtp password)
smtp_server (The smtp server)


Disclaimer: Above is a sample code only. Before implementing this code on a production website, please put necessary input validation code to avoid any misuse of this script. We take no liability of any misuse of this script as this script is only provided to give some guidance of the technologies involved.

KNOWLEDGE BASE HOME » 14. INFORMATION: CORPORATE & BUSINESS HOSTING Viewing Answer




Knowledgebase Manager

© Copyright Lounge Network 2001-2017