I recently wrote a console application to test various modes of SMTP. It's very basic and simple and I may expand it later.
It should be self-explanitory and only used as a basic testing utility.
This utility will NOT record any information entered. If you feel uncomfortable entering settings into some website or unknown app then this might work for you.
SMTPTester.zip (3.00 kb)
Here's the source code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace SMTPTester
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("########################################");
Console.WriteLine("# Welcome to Gary's world class smtp #");
Console.WriteLine("# tester. Select your option. #");
Console.WriteLine("# 1. Unathenticated SMTP #");
Console.WriteLine("# 2. Authenticated SMTP #");
Console.WriteLine("# 3. Authenticated SMTP with TLS (SSL) #");
Console.WriteLine("# 4. Exit program #");
Console.WriteLine("########################################");
Console.Write("#/> ");
var selectedOption = Console.ReadLine();
if (selectedOption == "4")
{
break;
}
Console.WriteLine("Enter the SMTP server");
Console.Write("#/> ");
var smtpServer = Console.ReadLine();
Console.WriteLine("Enter the SMTP port (default 25)");
Console.Write("#/> ");
var smtpPort = 25;
Int32.TryParse(Console.ReadLine(), out smtpPort);
Console.WriteLine("Enter the FROM address");
Console.Write("#/> ");
var mailFrom = Console.ReadLine();
Console.WriteLine("Enter the TO address");
Console.Write("#/> ");
var mailTo = Console.ReadLine();
Console.WriteLine("Enter the message subject");
Console.Write("#/> ");
var subject = Console.ReadLine();
Console.WriteLine("Enter the message body");
Console.Write("#/> ");
var body = Console.ReadLine();
switch (selectedOption)
{
case "1":
Console.WriteLine("Attempting to send mail");
var message = SendEmail(smtpServer, smtpPort, mailFrom, mailTo, subject, body);
Console.WriteLine(message);
break;
case "2":
Console.WriteLine("Please enter your username");
Console.Write("#/> ");
var username = Console.ReadLine();
Console.WriteLine("Please enter your password");
Console.Write("#/> ");
var password = Console.ReadLine();
Console.WriteLine("Attempting to send mail");
var authMessage = SendEmail(smtpServer, smtpPort, mailFrom, mailTo, subject, body, true, username, password);
Console.WriteLine(authMessage);
break;
case "3":
Console.WriteLine("Please enter your username");
Console.Write("#/> ");
var authUsername = Console.ReadLine();
Console.WriteLine("Please enter your password");
Console.Write("#/> ");
var authPassword = Console.ReadLine();
Console.WriteLine("Attempting to send mail");
var authSecureMessage = SendEmail(smtpServer, smtpPort, mailFrom, mailTo, subject, body, true, authUsername, authPassword, true);
Console.WriteLine(authSecureMessage);
break;
default:
Console.WriteLine("Incorrect option!");
break;
}
Console.WriteLine("Press a key to continue...");
Console.ReadLine();
Console.Clear();
}
}
private static string SendEmail(string server, int port, string from, string to, string subject, string body, bool authenticate = false, string user = null, string password = null, bool secure = false)
{
var smtpClient = new SmtpClient(server, port);
var message = new MailMessage(from, to, subject, body);
if (authenticate)
{
var credentials = new NetworkCredential(user, password);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = credentials;
if (secure)
{
smtpClient.EnableSsl = true;
}
}
try
{
smtpClient.Send(message);
return "Message sent successfully";
}
catch (SmtpException ex)
{
return String.Format("There was an error. {0}", ex.Message);
}
}
}
}
All stuff is as-is, no guarentee, blah blah blah, contact me for things.