Home > Uncategorized > Custom #Email #Autoresponder in c#

Custom #Email #Autoresponder in c#


I wanted to set up an autoresponder to my emails so that people would get notified over the christmas holidays that I’d be away. But I had quite specific requirements…

I tried http://www.listwire.com/fiach – but it required me to use a different email address, which wasn’t what I wanted.

So, I just coded my own autoresponder, a console app, that runs once a day, gathers emails via POP3, then replies to them using Amazon SES, then deletes the message again.

I set up my own POP3 server using Mailenable, – finding to my annoyance that the autoresponder in MailEnable didn’t work!, but then I went for this code (passwords removed)

using System;
using System.Configuration;
using System.IO;
using System.Net.Mail;
using System.Text;
using Pop3;

namespace Autoresponder
class Program
static void Main(string[] args)

Pop3Client pop3Client = new Pop3Client( );

pop3Client.Connect(“mail.xxx.com”, “all@xxxx”, “xxx”, false);

var strResponseFile = AppDomain.CurrentDomain.BaseDirectory + “autoresponder.txt”;
var strResponse = (new StreamReader(strResponseFile)).ReadToEnd();
var messages = pop3Client.List( );
foreach ( Pop3Message message in messages )
pop3Client.Retrieve( message );

Send(message.From, “Thank you for sending your CV”, strResponse, “noreply@outsourcetranslation.com”);
Console.WriteLine( “MessageId: {0}”, message.MessageId );
Console.WriteLine( “Date: {0}”, message.Date );
Console.WriteLine( “From: {0}”, message.From );

pop3Client.Disconnect( );


/// <summary>
/// Sends the specified recipient with reply to
/// </summary>
/// <param name=”recipient”>The recipient.</param>
/// <param name=”subject”>The subject.</param>
/// <param name=”body”>The body.</param>
/// <param name=”replyTo”>The reply to.</param>
public static void Send(string recipient, string subject, string body, string replyTo)
MailMessage mail = new MailMessage(ConfigurationManager.AppSettings[“FROM_ADDRESS”], recipient);
SmtpClient client = new SmtpClient();
client.Port = 25;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = ConfigurationManager.AppSettings[“MAILSERVER”];
client.Credentials = new System.Net.NetworkCredential(
mail.Subject = subject;
mail.Body = body;
mail.BodyEncoding = Encoding.UTF8;

It uses the Nuget package  Install-Package Pop3

And I installed this on my server as a scheduled task.

Categories: Uncategorized
  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 )

Connecting to %s

%d bloggers like this: