SMTP .NET Component
The SMTP .NET Component provides an easy to use API to send email messages.
 
Features
- 100% managed C# - A highly scalable solution with no dependencies on 3rd party libraries.
- Easily add one or more attachments to email messages
- HTML message support
- Email address helper classes for creating and parsing email addresses.
- Royalty-Free Distribution - No runtime fees!
- Easily retrieve attachments from email messages.
- Serialization support allows you to easily store email messages to disk or a database
- International support for multiple character sets.
- Thread safe - Critical code blocks are synchronized for use by multiple threads.
- Event Model - Multiple events for capturing SMTP activity
- Integrated Help - Automatic integration of Help 2.0 documentation for Visual Studio .NET
Code Example
The following C Sharp example demonstrates dynamically creating and sending an Email message using the Smtp .NET Component.
/*
* SmtpExample.cs
*
* Copyright (c) 1999-2005 JSCAPE, LLC
* 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information of
* JSCAPE ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with
* the terms of the license agreement you entered into with JSCAPE.
*/
using System;
using System.IO;
using System.Text;
using System.Threading;
using Jscape.Email;
namespace SmtpExample {
public class SmtpExample {
public Smtp mySmtp = null;
public SmtpExample(string hostname){
mySmtp = new Smtp(hostname);
mySmtp.Debug = false;
// Subscribe to events
mySmtp.ConnectedEvent += new Smtp.ConnectedEventHandler(OnConnected);
mySmtp.DisconnectedEvent += new Smtp.DisconnectedEventHandler(OnDisconnected);
mySmtp.DataReceivedEvent += new Smtp.DataReceivedEventHandler(OnDataReceived);
mySmtp.CommandSentEvent += new Smtp.CommandSentEventHandler(OnCommandSent);
// create email message
EmailMessage message = new EmailMessage();
message.To = "ceo@ourserver.com, cto@ourserver.com";
message.Cc = "sales@ourserver.com";
message.From = "hr@ourserver.com";
message.SetSubject("New employee Jän Freidman", "iso-8859-1");
message.SetBody("Please welcome our newest employee.");
// add attachment
Attachment att = new Attachment(@"D:\hr\employees\resumes\freidman.doc");
message.AddAttachment(att);
// Connect to smtp server
mySmtp.Connect();
// Send email message;
mySmtp.Send(message);
// your server may require a slight delay in order to respond
Thread.Sleep(100);
// Disconnect from smtp server
mySmtp.Disconnect();
}
public static void Main() {
// default mail server
string hostname = "mail.ourserver.com";
// prompt for mail server
Console.WriteLine("Smtp server: "+hostname);
if ((hostname = Console.ReadLine()) != "") {
SmtpExample smtpexample = new SmtpExample(hostname);
}
}
public void OnConnected(object sender, SmtpConnectedEventArgs e) {
Console.WriteLine("Connected to {0}", e.Host);
}
public void OnDisconnected(object sender, SmtpDisconnectedEventArgs e) {
if (mySmtp.IsConnected()) {
mySmtp.Disconnect();
}
Console.WriteLine("Disconnected.");
}
public void OnDataReceived(object sender, SmtpDataReceivedEventArgs e) {
Console.WriteLine("Response: "+e.Response);
}
public void OnCommandSent(object sender, SmtpCommandSentEventArgs e) {
Console.WriteLine("Command: "+e.Command);
}
}
}
 
|
|