System.Web.Mail Sample C# and VB .NET Script

The following scripts use SMTP Authentication to send mail from your script -
C#:
<% @Page Language="C#" %>
<% @Import Namespace="System.Web.Mail" %>
<%
MailMessage mail = new MailMessage();
mail.To = "[email protected]";
mail.From = "[email protected]";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "PASSWORD"); //set your password here
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );

%>

VB .NET:
<% @Page Language="VB" %>
<% @Import Namespace="System.Web.Mail" %>
<%
Dim mail As New MailMessage()
mail.To = "[email protected]"
mail.From = "[email protected]"
mail.Subject = "this is a test email."
mail.Body = "Some text goes here"
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") 'basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "[email protected]") 'set your username here mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "PASSWORD") 'set your password here
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)

%>


  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

I am receiving System.Security.SecurityException or That assembly does not allow partially trusted callers.

When running your application you may see: That assembly does not allow...

How can I redirect one URL to another on ASP .NET?

Our ASP plans have the following installed:...

Cryptography with ASP .NET

A customer received the following error when attempting to create a RSACryptoServiceProvider from...

I am getting a 404 error on the secondary pages of my MVC application. Why?

To resolve the 404 error issues on secondary pages of a ASP .NET MVC applications, you will need...

My site is showing the following error: HTTP Error 503. The service is unavailable.

The error HTTP Error 503. The service is unavailable. generally means that your application pool...