ANSMTP Developers Center > Using ANSMTP in .NET Framework SDK

Introduction

This tutorial introduces how to use ANSMTP in .NET Framework SDK without Visual Studio.NET. If you use Visual Studio.NET as your development tool, please refer to the corresponding tutorials.

Installation and Deployment

You should download the ansmtp installer and install it on your machine at first. If you want to distribute or deploy ansmtp without ansmtp installer, please click here to learn more.

Import ANSMTP to .NET assembly

In "DOTNET Assembly" directory of ANSMTP installation directory, there is a file "ANSMTPLib.dll" which is the run-time file of ANSMTP in dotnet common language assembly. You can also generate "ANSMTPLib.dll" by "tlbImp" tool in .NET Framework SDK.

[run this command under dos prompt]
tlbimp "C:\Program Files\AdminSystem.NET\ANSMTP\ANSMTP.dll" /namespace:ANSMTPLib /out:ANSMTPLib.dll

Simple project

Create a file in notepad called "test.cs" with the following code:

using System;
using ANSMTPLib;

namespace CSharpSendEmail
{
  class SendEmail
  {
    public static void Main( string[] args )
    {
      string sender	= "";
      string rcpt	= "";
      string server	= "";
      string subject	= "";
      string body	= "";
      
      Console.WriteLine( "Welcome to ANSMTP CSharp Sample");
      while( sender == "" )
      {
        Console.WriteLine( "please input sender's email address" );
        sender = Console.ReadLine().Trim();
      }
      
      while( rcpt == "" )
      {
        Console.WriteLine( "Please input recipient's email address" );
        rcpt = Console.ReadLine().Trim();
      }
      
      Console.WriteLine( "Please input your SMTP server address" );
      Console.WriteLine( "If you don't have a SMTP server, please press enter" );
      Console.WriteLine( "ANSMTP will send email via DNS lookup" );
      
      server = Console.ReadLine().Trim();
      Console.WriteLine( "Please input email subject" );
      subject = Console.ReadLine().Trim();
      
      Console.WriteLine( "Please input email body" );
      body = Console.ReadLine().Trim();
      
      OBJClass oSmtp = new OBJClass();
      
      oSmtp.RegisterKey = "your license code";
      oSmtp.Reset();
      oSmtp.FromAddr = sender;
      oSmtp.Subject = subject;
      oSmtp.BodyText = body;
      oSmtp.ServerAddr = server;
      oSmtp.AddRecipient( rcpt, rcpt, 0 );
      
      // Add file attachment
      // oSmtp.AddAttachment( "c:\\test.doc" );
      
      Console.WriteLine( "From: {0}", sender );
      Console.WriteLine( "To: {0}", rcpt );
      Console.WriteLine( "Server: {0}", server );
      Console.WriteLine( "Subject: {0}", subject );
      Console.WriteLine( "Start to send email to {0} ...", rcpt );
      
      if( oSmtp.SendMail() == 0 )
        Console.WriteLine( "Sending email to {0} succeeded!", rcpt );
      else
        Console.WriteLine( oSmtp.GetLastErrDescription());
        
      oSmtp = null;
    }
  }
}

Compile this project

Copy "ANSMTPLib.dll" to the same directory as "test.cs"

[run under DOS prompt]
set CompilerPath=%WINDIR%\Microsoft.NET\Framework\v1.0.3705
%CompilerPath%\csc /reference:ANSMTPLib.dll /out:SendEmail.exe test.cs

Note: the compiler of Visual Basic.NET is vbc and the compiler of JScript.NET is jsc.

Now, try to run SendEmail.exe.

More Samples

Please refer to DOTNET SDK samples (C#, VB.NET, JScript.NET) in ANSMTP installation package.

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET
VIP@EmailArchitect.NET(Registered User)

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your smtp server bounced our reply. In this case, please try to use another email address to contact us. Your Hotmail or Yahoo email account is recommended.



2001-2008 © Copyright AdminSystem Software Limited. All rights reserved.   About us  Site Map