VS.NET 2010/2012 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
aspNetMime

RSS feed for aspNetMime Subscribe to category: aspNetMime

aspNetMime: Handling InLine Parts

by Dave 25. November 2011 06:21

Every few months, I get a question from a developer about aspNetMime not properly finding all the attachments in an email.

Almost all of the time, these attachments are actually In-Line parts. Rather than sending files as attachments, some mail clients will actually sent these 'attachments' as In-Line parts.

To reference these parts, use the MimeMessage.InLineParts collection. Another way to reference all attachments and in-line parts is too call the MimeMessageAttachmentInLineParts() method. This method will find every attachment + in-line part. Below is a code example to demonstrate this functionality.

 

string path = "c:\\temp\\sample.eml";
MimeMessage m = MimeMessage.ParseFile( path );

//get attachments and in-line parts
MimePartCollection mpc = m.AttachmentInLineParts();
Response.Write( "total parts: " + m.RetrieveAllParts().Count.ToString

//loop through the attachments+in-line parts, write out the name
foreach( MimePart mp in mpc)
{
	Response.Write( mp.AttachmentName() );
}



As always, if anyone has any questions, feel free to email me using the Contact Us page.

Thanks,
Dave Wanta

Tags:

aspNetMime

aspNetMime: Using it in a ASP (COM) Applicatioin

by Dave 29. September 2011 04:00

An evaluator, Chuck, had a request to use aspNetMime from a classic ASP (COM) application.

Normally, aspNetMime is used in .NET application (C#, VB.NET, etc.. winforms, windows services, and ASP.NET applications). However, occasionally a developer will need to use our assemblies (in this example, aspNetMime) from classic COM applications.

To do this, we must first download the aspNetMime.dll from the website (www.advancedintellect.com)

By default, when you run the aspNetMime.msi install file, it will be installed in the GAC (global assembly cache). However, if you want to manually do this (or if you moved the aspNetMime.dll to a new server), you can use the gacutil.exe (provided by VS.NET).

From a command prompt, call:

        gacutil.exe /I aspNetMime.dll

Once aspNetMime is installed in the GAC, it must be exposed for COM (ASP, VBScript, VB4+). To do this, you need to use the regasm.exe tool (also provided by VS.NET).

To do this, again from a command prompt, execute the following command:

        regasm.exe aspNetMime.dll

Regasm.exe will create a COM wrapper around the aspNetMime.dll, and install the required registry entries, so that aspNetMime can be called for COM.

Once that is done, aspNetMime can now be used in a classic ASP page.  Here is an example, that reads in an email file, and displays the subject and body on a page:

<% Option Explicit%>

<%
Dim mime
Dim lic
Dim subject
Dim plainText
Dim htmlText

'Load the license file
 Set lic = Server.CreateObject( "aspNetMime.MimeMessageLicense" )
 lic.LoadLicenseFile  "c:\aspNetMime.xml.lic"  'loads the license in memory
 
'create the MimeMessage object
 Set mime = Server.CreateObject( "aspNetMime.MimeMessage" )

'load the test email
mime.LoadFromFile( "c:\temp\aspTest.eml")

'read the subject
subject = mime.Subject.Value
Response.Write("<BR>Subject: " + subject)

'get the plain text body (if one exists)
if( not mime.TextMimePart is Nothing ) then
 plainText= mime.TextMimePart.DecodedText
 Response.Write("<HR>")
 Response.Write(plainText)
End if

'get the Html body (if one exists)
if( not mime.HtmlMimePart is Nothing ) then
 htmlText = mime.HtmlMimePart.DecodedText
 Response.Write("<HR>")
 Response.Write(htmlText)
End if
%>

As always, if anyone has any questions, feel free to contact me using the Contact Us page, and referene this article.

Thanks!
Dave Wanta

Parsing Cell Phone (mobile) generated emails

by Dave 9. November 2010 02:29

I have a number of customers who need to parse cell phone (mobile) generated emails. These emails come in configurations I never dreamed possible. Although they are technically Mime compliant, their individual parts can be ordered strangely, or have unique headers that normally aren't found in a standard message.

I was sent an email request from a developer (Thanks Cara!) about parsing a T-Mobile generated message. She needed to find and extract the text body part. If a text body part wasn't found, then the html body part was to be found, and converted to plain text. The other requirement was to find all of the images, and download (save) them to a directory.

Below is a code example is something I whipped up for her. She used it as a basis to get started with her application. Error checking has been left out, to keep the code short, workable, but complete.

As always, if anyone has any questions or comments, please let me know.

Thanks!
Dave Wanta

string path =  "t_mobile.eml";

MimeMessage m = MimeMessage.ParseFile( path );

MimePart textPart = m.TextMimePart;
if( textPart == null )
{
	//try and find it, by finding the first inline text part
	MimePartCollection inlineParts = m.InLineParts;
	if( ( inlineParts != null ) && ( inlineParts.Count >0 ) )
	{
		foreach( MimePart part in inlineParts )
		{
			if( (part.Name != null ) && ( part.Name.EndsWith(".txt") ) && ( part.ContentTypeString == "text/plain") )
			{
				//then we found our part
				textPart = part;
				break;
			}
		}
	}
}

string plainText = string.Empty;
if( textPart != null )
{
	plainText = textPart.DecodedText();
}

if( plainText.Length == 0 )
{
	//find the first html part.
	//get the plain text from the html part

	foreach( MimePart part in m.RetrieveAllParts() )
	{
		if( (part.ContentTypeString != null ) && ( part.ContentTypeString.ToLower() == "text/html") )
		{
			string html = part.DecodedText();
			//convert the Html to plain formatted text
			plainText = Utility.ConvertHtmlToText( html).Trim();
			break;
		}
	}
}

//extract all images, and save them to the temp directory
foreach( MimePart part in m.RetrieveAllParts() )
{
	if( part.IsImage() )
	{
		//normally, would need to check for images that already have the same filename
		//and rename accordingly
		//in this example, just save the images to the temp directory
		part.Save("c:\\temp\\");
	}
}

Using Advanced Intellect's Products in VS2010/2012

by Dave 9. November 2010 01:46

** NOTE: ALL OF OUR PRODUCTS RUN ON ALL VERSIONS OF .NET. **

The instructions below are for people using VS2010 and beyond.

                                                        --------------------------

As more and more people are upgrading to VS2010, and beyond, I am getting more of the following emails:

aspNetEmail (or any of our other products) doesn't work in later versions of Visual Studio. I usually get one of the following errors:

"aspNetEmail is not declared, it may be inaccessible due to its protection level."

Or

"The referenced assembly "…" could not be resolved because it has a dependency upon System.Web (or some other internal .NET namespace).  Please remove references to assemblies not in the targeted framework or consider retargeting your project"

Usually these exceptions occur when the developer is building a client side application.

Starting in VS2010, VS tries to be too smart for it's own good.  When you build a client application (console.exe, winform, etc…) VS limits the number of namespaces you need access too, because it thinks you shouldn't need them.

To change this behavior, what you need to do, is change the target framework from a subset of namespaces, to all of them.

To change this, in VS.NET Solution Explorer, Right-Click on  your project, an select Properties.
 
On the Application tab, set the Target Framework to be ".NET Framework XX". By default it is set to ".NET Framework XX Client Profile".  Press Ctrl-S for save, and you are done.

Below are 2 pictures that display changing the target framework.

As always, if anyone has any questions, feel free to contact me.

Thanks!
Dave Wanta

 

C# Screenshot:

 

VB.NET Screenshot (this option is found under the Compile tab. Then, click the "Advanced Compile Option" button.

 

 

 

Testimonial

I must say that I love your product. "

NIRAV

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