MIME Sample in VB.Net

Hi

I have just downloaded the latest version of ASPOSE.Network and I keep getting an error at the line shown in red when I try to run the MIME sample in VB.Net. We are currently in the process of evaluating your library to explore the possibility of extarct embedded attachments from Outlook MSG files

Dim msg As Aspose.Network.Mail.MailMessage

msg = New Aspose.Network.Mail.MailMessage

If (Me.fileDialog.FileName.EndsWith(".msg")) Then

'// load and parse an .msg file

msg = Aspose.Network.Mail.MailMessage.Load(textBox_FilePath.Text, Aspose.Network.Mail.MessageFormat.Msg)

The error message that I get is as follows and I get it at the line of code shown above in red

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."

Any help will be greatly appreciated.

Thanks

John

Hello John,

Thank you for your post!

Could you attach such one .msg file here or send it to GuangZhou@aspose.com?

Best regards!

Hi

I just sent you a sample msg file.

Thanks

John

Hello John,

Thank you for your post!
I’ve received your msg file. Get back to you soon.

Best regards.

Hello John,

I’ve tested the file you sent me. It seems normal here. By the way, the file you sent me is an EML file, not a MSG file. could you please try the following code samples?

Aspose.Network.Mime.MimeMessage msg;
msg = Aspose.Network.Mime.MimeMessage.Load(@“d:\download\FW_ This is rich text sample.eml”);
//print out msg
if (msg.From != null)
Console.Write("\n From: " + msg.From.ToString());
if (msg.To != null)
Console.Write("\n To: " + msg.To.ToString());
if (msg.Subject != null)
Console.Write("\n Subject: " + msg.Subject);

Console.WriteLine("\n Mail body: “);
if (msg.TextBody != null)
Console.Write(”\n" + msg.TextBody);
if (msg.HtmlBody != null)
Console.Write("\n" + msg.HtmlBody);

//save all the attachments to file
foreach (Aspose.Network.Mail.Attachment attachment in msg.Attachments)
{
attachment.Save(@“d:” + attachment.Name);
}
//save the msg as mht page:
msg.Save(@“d:\test.mht”, Aspose.Network.Mail.MessageFormat.Mht);

//pause screen
Console.Read();

The sample above will print out the mail message information to screen, and save all the attachments.

Best regards.

And the VB.NET version:

Sub Main()

Dim msg As Aspose.Network.Mime.MimeMessage
msg = Aspose.Network.Mime.MimeMessage.Load(“d:\download\FW_ This is rich text sample.eml”)
‘//print out msg
If (msg.From IsNot Nothing) Then
Console.Write(vbCrLf & "From: “ & msg.From.ToString())
End If
If (msg.To IsNot Nothing) Then
Console.Write(vbCrLf & ” To: “ & msg.To.ToString())
End If
If (msg.Subject IsNot Nothing) Then
Console.Write(vbCrLf & ” Subject: “ & msg.Subject)
End If

Console.WriteLine(vbCrLf & ” Mail body: ")

If (msg.TextBody IsNot Nothing) Then
Console.Write(vbCrLf & msg.TextBody)
End If
If (msg.HtmlBody IsNot Nothing) Then
Console.Write(vbCrLf + msg.HtmlBody)
End If

’//save all the attachments to file
For Each attachment As Aspose.Network.Mail.Attachment In msg.Attachments
attachment.Save("d:" & attachment.Name)
Next
'//save the msg as mht page:
msg.Save(“d:\test.mht”, Aspose.Network.Mail.MessageFormat.Mht)

'//pause screen
Console.Read()
End Sub