Problems with EmbeddedObjects

Hi, I'm trying to Add Embedded objects to a msg. Perhaps i'm overseeing something, but Vs2003, vb.net, asp.net 1.1. complains about this statement:-

msg.AddEmbeddedObjects

C:\Inetpub\wwwroot\ApoOnline3\MailingHistory\ShowMailingActie2.aspx.vb(307): 'AddEmbeddedObjects' is not a member of 'Aspose.Network.Mail.MailMessage'.

What is going wrong? I made a reference to Aspose.Networks.Mail (where i can)..

Many thanks for your help ...

Aat Jan

Hello,

Thank you for your post!
It looks like you are using demo codes from former versions of Aspose.Network. For current versions, this is an example to add embedded objects into a MailMessage:

'Create a new instance of MailMessage
Dim msg As New Aspose.Network.Mail.MailMessage
msg.To = "to@aspose.com"
msg.From = "from@aspose.com"
msg.Subject = “test subject”

'Add an embedded resources, a jpg file in this case
Dim obj As Aspose.Network.Mail.LinkedResource
obj = New LinkedResource(System.IO.File.Open(“c:\test.jpg”, IO.FileMode.Open), Aspose.Network.Mime.MediaTypeNames.Image.Jpeg)
'ContendId can be used to refer to this jpg file
obj.ContentId = “logo”
'Add resources
msg.LinkedResources.Add(obj)

'Using ContendId to locate the embedded resource
msg.HtmlBody = "here’s an embedded image:"

msg.Save(“test.eml”)

We are truely sorry for your inconvenience due to our version changes. Related documentation WILL be updated in a timely fashion and we will answer your questions here as first priority.

Best regards!

is this example the same for msg.save as html …

Hi,

Saving the mail message to file is for testing purpose. We could open that eml file by outlook to check out the embeded image.
Currently we could save MailMessage as .eml, .mht or .msg files. The sample above save the message as .eml file.

msg.Save(“test.mht”, Aspose.Network.Mail.MessageFormat.Mht)

The code above can save a mail message as .mht file.

Hi, thanks for all your help. I'm still not there where i want to be. Do you have an example where AsposeWords and Aspose Mail works together: with the conversion from .doc to htm the resulting html file is referring to images with an absolute path and filename. Now i have to replace in the htm document all the absolute path images with this code. I'm struggling with this subject now for day's and getting uncomfortable ....

Aat Jan

Dear Aat,

Thank you for you post!
Are you trying to send a .doc file as an email? that is, you want to
1. Convert the .doc file to .htm
2. Construct a MailMessage from that .htm file and send it
And you want a better way to do this, am i understanding this right?

Best regards.

Hi,

Yes, thats my aim. Why Word: because most of the professional users of the portal i'm building are using word. The receiver ot the email's are end-users. Not a lot of them has a word version (or they are using an illegal one. So therefore i see html mail as a good way of working.

The manual way (ask word to save it as a htm) is not ok, because it must completely be weboperated ...

Aat Jan

Is the htm file that AsposeWords produces protected? Perhaps that is the reason why i cannot change the referrals to the images ...

Aat Jan

Hello Aat,

Thank you for your post!
I will contact Aspose.Word and provide a solution for this Word and Mail coupling A.S.A.P, probably in several days.

Thanks again for your patience.

Hi, thanks, would be great!!!

Aat Jan

Hello Aat,

Thank you for your patience.
There’s no direct way to transform a .doc to mail message currently. however, we could save the .doc file as html file and import that html file to a mail message.
Here is the link to the sample project (vs 2005 VB console project):

[http://www.aspose.com/products/aspose.network/word2Mail.zip](https://forum.aspose.com/products/aspose.network/word2mail.zip)

The sample project follows these steps:

  1. open an .doc file and save as html to a tempory directory:

Dim doc As Document
doc = New Document("…" + docName)

'create a tempory directory for this document to save to
Dim tmp As String
tmp = Guid.NewGuid().ToString()
Directory.CreateDirectory(tmp)

'save document as html
docName = docName.Replace(".doc", “.html”)
doc.Save(tmp + “” + docName, SaveFormat.Html)

When saved as html files, all the images inside that .doc file will be saved as .png files. We have to import those .png files as embedded resources later

  1. Create mail message from html files

Dim files() As String
files = Directory.GetFiles(tmpPath)

For Each file As String In files

Dim fileName As String
'get the file name + file extension part. omit the directory part
fileName = file.Split("")(1)

Dim index As Integer
index = html.IndexOf(fileName)
'only process png file as an example
If index >= 0 And fileName.Contains(".png") Then
Dim res As LinkedResource
res = New LinkedResource(file, “Image/PNG”)
res.ContentId = fileName
'add “cid:” in the url to retrieve embedded resource
html = html.Replace(fileName, “cid:” + fileName)
msg.LinkedResources.Add(res)
End If
Next

msg.HtmlBody = html

  1. delete all the tempory files and directory

Test document:

Generated mail message:

Issues:
If you are writing a web application, make sure you have permission to read from and write to the server file system.

Best regards.