VS.NET 2010 Users Click Here   

HOMECONTACT PRODUCTS DOWNLOADS PURCHASE TESTIMONIALS FORUMS COMPANY CONTACT
Home
Products
Downloads
Purchase
Licensing
Licensing FAQ
Software Updates
Support Forums
Testimonials
Feature Requests
Guarantee
About Us
Contact Us
Hosting Companies
Privacy Policy
   
Shopping Cart


Search

aspNetPOP3 and aspNetEmail: Creating an email "Proxy" to process and resend email

by Dave 27. September 2011 13:44

Ian (on the forums) had a question about how to download email from a POP3 server, process it using his own custom rules, and then resending it.

The trick to resending it, is that he wanted to the original email to be resent and unmodified. This is a little different than the usual request. Usually, developers need to modify the original email in some fashion, rebuild it, and resend it.

In this example, Ian wanted to resend the email, as if it's never been sent. It needs to dynamically determine who to send it to, and forward it on. This makes his application work like an email proxy of sorts.

Below is a code example that would get Ian started on something like this.

As always, if anyone has any questions about this, feel free to use the Contact Us page, to send any questions.

Thanks,
Dave

Here is the code

void Execute()
{
	//connect to the pop3 server
	POP3 pop = new POP3();
	pop.Server = "mail.blah.com";
	pop.Username = "dave@blah.com";
	pop.Password = "test";

	//enable logging
	pop.LogPath = "c:\\pop.log";

	//login
	pop.Login();

	//get the first message as text
	string content = pop.GetMessageAsText(0);

	//process the message
	Process( content );
	
	ResendAsOriginal( content );

	//if we want to delete the message, uncomment the following lines
	//pop.Delete(0);
	//pop.CommitDeletes();

	//disconnect
	pop.Disconnect();
}

void Process( string emailContent )
{
	//create the MimeMessage
	MimeMessage m = MimeMessage.ParseString( emailContent );

	//do whatever we need to with the extracted data
	if( m.Subject  != null )
	{
		string subject = m.Subject.Value;
	}
}

void ResendAsOriginal( string emailContent )
{
	//create the EmailMessage object
	EmailMessage msg = new EmailMessage();

	//set the server
	msg.Server = "192.168.1.106";

	//set the TO and FROM values
	//these may need to be dynamic, and depend up on the
	//value of emailContent
	//for this example, they are hard coded

	msg.To = "CustomerService@blah.com";
	msg.FromAddress = "proxy@myserver.com";
	msg.SmtpData = emailContent;

	msg.Send();
}




 

 

Testimonial

I love your contol, WAY COOL. I was using System.Web.Mail and could not get it to send a BCC. no error, it just would not do it. I worked for two days, then downloaded you demo and had it working in 15min. I would highly recommend your control! "

Mike | Webwizer

Read more testimonials
ListNanny aspNetDNS aspNetEmail aspNetPOP3 aspNetMX aspNetMIME aspNetPING aspNetTraceRoute aspNetIMAP aspNetMHT