Home > ASP.Net > Test Emails in ASP.NET without a Mail Server

Test Emails in ASP.NET without a Mail Server


Hi all,

try this example to Test Emails in ASP.NET without a Mail Server

1) Open VS 2005 and create new web site

2) Add new Web.Config and add these lines

<system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\Mails\"/>
      </smtp>
    </mailSettings>
  </system.net>

3) Add new asp Page and add button from ToolBox and in code behind add the following code :-


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage message = new MailMessage("abc@somedomain.com", "abc@abcdefgh.com", "Newsletter", "This is a test mail");
 SmtpClient client = new SmtpClient("localhost");
 client.Send(message);
    }
}

Hope this helps you

Good Luck

Advertisements
Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: