ANSMTP Developers Center > Using ANSMTP in .NET Framework SDK
Important notice:* This product has integrated to EASendMail SMTP Component, Please use EASendMail SMTP Component instead of ANSMTP SMTP Component.
Related Links:
Send Email in VB.NET with EASendMail SMTP Component
Send Email in C# with EASendMail SMTP Component
Send Email in Managed C++ with EASendMail SMTP
Component
Email Queue with EASendMail Service
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.
How to send email with SMTP server;
How to send email without specified SMTP server (via DNS lookup);
How to add file attachment to an email;
How to compile this project.
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 "AOSMTPLib.dll" which is the run-time file of ANSMTP in dotnet common language assembly. You can also generate "AOSMTPLib.dll" by "tlbImp" tool in .NET Framework SDK.
[run this command under dos prompt] tlbimp "C:\Program Files\AdminSystem.NET\ANSMTP\AOSMTP.dll" /namespace:AOSMTPLib /out:AOSMTPLib.dll
Simple project
Create a file in notepad called "test.cs" with the following code:
using System;
using AOSMTPLib;
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();
AOSMTPLib.MailClass oSmtp = new AOSMTPLib.MailClass();
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 "AOSMTPLib.dll" to the same directory as "test.cs"
[run under DOS prompt] set CompilerPath=%WINDIR%\Microsoft.NET\Framework\v1.0.3705 %CompilerPath%\csc /reference:AOSMTPLib.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.
|