Mime mail lotus script and images not visible in some web mailbox (eg: hotmail.com, libero.it ....)

Dear all,i write a lotus script agent that send e-mail in Mime format with HTML and two images.

When i send the email in my personal web mailbox eg: myname@mycompany.com the HTML and images are correctly visible

When i send the email in other web mailbox eg: myname@hotmail.com or myname@libero.it or some others mailbox, the HTML is good but the images is not correctly visible.

viceversa, if i send email in this web mailbox with my lotus notes mail db with “Format for messages addressed to internet addresses: MIME Format” set in my location the message are correctly “convert” in HTML format and images is correctly visible.

follow i attach the code of my Mime lotus script agent:

Sub Initialize

On Error Goto CheckError

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim parent As NotesMimeEntity

Dim child1 As NotesMimeEntity

Dim child2 As NotesMimeEntity

Dim child3 As NotesMimeEntity

Dim header As NotesMimeHeader

Dim dataDir As String

Dim stream As NotesStream

Dim prompt As String

Dim recipients As Variant



Dim ws As New NotesUIWorkspace

Dim docCtx As notesdocument

Dim uidoc As NotesUIDocument

Set uidoc = ws.CurrentDocument

Set docCtx = uidoc.document



session.ConvertMime = False    ' We do want Notes to convert MIME to Rich Text



Set db = session.CurrentDatabase

Set doc = db.CreateDocument

Call doc.ReplaceItemValue("Form", "Memo")

Call doc.ReplaceItemValue("Subject", "Doc created " _

& Format$(Now, "dd mmm yyyy hh:nn:ss AM/PM"))



' Figure out the path to the domino\icons directory under the user's data directory

dataDir = session.GetEnvironmentString("Directory", True)

If Right(dataDir, 1) <> "\" Then dataDir = dataDir & "\"

'dataDir = dataDir & "domino\icons\"



dataDir = "C:\Documents and Settings\dspingi\Desktop\"

img1$ = "img1.gif"

img2$ = "img2.gif"



' Create all the Entities - one parent, two children. 

Set parent = doc.CreateMIMEEntity

Set child3 = parent.CreateChildEntity

Set child2 = parent.CreateChildEntity

Set child1 = parent.CreateChildEntity(child3)    ' Create so that children 1 & 2 are siblings



' Update all the header information. At this point we cannot create another "Content-Type"

' entity on the parent, but we can update the existing value

Set header = parent.GetNthHeader("Content-Type")

Call header.SetHeaderValAndParams({multipart/alternative; boundary="} _

& child1.BoundaryStart & {"})

Set header = child2.CreateHeader("Content-ID")

Call header.SetHeaderVal("<_1_" & doc.UniversalID & ">")



Set header = child3.CreateHeader("Content-ID")

Call header.SetHeaderVal("<_2_" & doc.UniversalID & ">")



' Build the entire HTML table, including a reference to an image that is yet to come (its ID 

' was created above). This HTML goes into child 1

Set stream = session.CreateStream



Call stream.WriteText({<table width="750" border="0" cellspacing="0" cellpadding="0">})

Call stream.WriteText({<tr valign="top"><td width="747" bgcolor="#E0F1FF">})

Call stream.WriteText({<table width="750" border="1" cellspacing="0" cellpadding="0">})

Call stream.WriteText({<tr valign="top"><td width="737" bgcolor="#F7F7F7">})

Call stream.WriteText({<table width="750" border="0" cellspacing="0" cellpadding="0">})

Call stream.WriteText({<tr valign="top"><td width="206" bgcolor="#C2EFFF">})

Call stream.WriteText({<img src=cid:_1_} & doc.UniversalID & {>})

Call stream.WriteText({<td valign="middle" width="501" bgcolor="#C2EFFF">})

Call stream.WriteText({<font face=Arial size=3 color=white><b>})

Call stream.WriteText("Free text")

Call stream.WriteText({</font>})

Call stream.WriteText({</td></tr>})

Call stream.WriteText({<td align="top" align="top" valign="top">})

Call stream.WriteText({<img src=cid:_2_} & doc.UniversalID & {>})

Call stream.WriteText({</td>})

Call stream.WriteText({<td align="top" valign="top" width="501" bgcolor="#F7F7F7">})

Call stream.WriteText({<p align="justify">})

Call stream.WriteText({<font face=Arial size=2>})

Call stream.WriteText("Free text body")

Call stream.WriteText({</font>})

Call stream.WriteText({</p>})

Call stream.WriteText({</td></tr>})

Call stream.WriteText({<tr valign="top"><td width="722" bgcolor="#C2EFFF" colspan="2"><b>internal comunication</b></td></tr>})

Call stream.WriteText({</table>})

Call stream.WriteText({</td></tr>})

Call stream.WriteText({</table>})

Call stream.WriteText({</td></tr>})

Call stream.WriteText({</table>})



Call child1.SetContentFromText(stream, "text/html", ENC_NONE)

Call stream.Truncate



' Bring the image into its entity (parent 2)

Set stream = session.CreateStream

If Not stream.Open(dataDir & img1$, "binary") Then

	Msgbox "Could not open " & dataDir & img1$, 16, "Open failed"

	Goto ExitSub

End If

If stream.Bytes = 0 Then

	Msgbox "File " & dataDir & img1$ & " has no content", 16, "No Content"

	Goto ExitSub

End If

Call child2.SetContentFromBytes(stream, "image/gif", ENC_NONE)

Call child2.EncodeContent(ENC_BASE64)

Call stream.Close



'----------------------

'Call stream.Truncate

Set stream = session.CreateStream

If Not stream.Open(dataDir & img2$, "binary") Then

	Msgbox "Could not open " & dataDir & img2$, 16, "Open failed"

	Goto ExitSub

End If

If stream.Bytes = 0 Then

	Msgbox "File " & dataDir & img2$ & " has no content", 16, "No Content"

	Goto ExitSub

End If

Call child3.SetContentFromBytes(stream, "image/gif", ENC_NONE)

Call child3.EncodeContent(ENC_BASE64)

Call stream.Truncate

Call stream.Close



recipients = "username@domain.ext"

Call doc.Send(False, recipients)

ExitSub:

session.ConvertMime = True    ' Reset the value



Exit Sub

CheckError:

Msgbox Error + ":" + Cstr(Erl)

Exit Sub

End Sub


Thank you very much for the help!

i wish also to specify that the above code has been modified by me from the following source code found in this forum, also this code have the problem of the images not visible in some web mailbox:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim parent As NotesMimeEntity

Dim child1 As NotesMimeEntity

Dim child2 As NotesMimeEntity

Dim header As NotesMimeHeader

Dim dataDir As String

Dim stream As NotesStream

Dim prompt As String

Dim recipients As String



session.ConvertMime = False    ' We do want Notes to convert MIME to Rich Text



Set db = session.CurrentDatabase

Set doc = db.CreateDocument

Call doc.ReplaceItemValue("Form", "Memo")

Call doc.ReplaceItemValue("Subject", "Doc created " _

& Format$(Now, "dd mmm yyyy hh:nn:ss AM/PM"))



' Figure out the path to the domino\icons directory under the user's data directory

dataDir = session.GetEnvironmentString("Directory", True)

If Right(dataDir, 1) <> "\" Then dataDir = dataDir & "\"

dataDir = dataDir & "domino\icons\"

'Msgbox dataDir



' Create all the Entities - one parent, two children. 

Set parent = doc.CreateMIMEEntity

Set child2 = parent.CreateChildEntity

Set child1 = parent.CreateChildEntity(child2)    ' Create so that children 1 & 2 are siblings



' Update all the header information. At this point we cannot create another "Content-Type"

' entity on the parent, but we can update the existing value

Set header = parent.GetNthHeader("Content-Type")

Call header.SetHeaderValAndParams({multipart/alternative; boundary="} _

& child1.BoundaryStart & {"})

Set header = child2.CreateHeader("Content-ID")

Call header.SetHeaderVal("<_1_" & doc.UniversalID & ">")



' Build the entire HTML table, including a reference to an image that is yet to come (its ID 

' was created above). This HTML goes into child 1

Set stream = session.CreateStream



Call stream.WriteText({<table border="1" width="700" align="center" cellspacing=0 cellpadding=1>})

Call stream.WriteText({<tr><td>})

Call stream.WriteText({<img src=cid:_1_} & doc.UniversalID & {>})



Call stream.WriteText({</td><td><p align="justify">Format your messages and reports using techniques that combine MIME, HTML, and LotusScript rich text classes. This article demonstrates advanced formatting and data-handling techniques: perking up forms in the Notes client (e.g., creating variable-length tables to handle dynamic data); displaying back-end rich text updates in Notes without saves (e.g., building reports that instantly incorporate user inputs); controlling the formatting of content (including embedded images and multiple entities) in automatically generated Internet messages; and mixing MIME code with rich text to incorporate images and URLs in memos and reports. Demonstration code for all of these techniques is available from THE VIEW Web site.</p></td></tr></table>})



'<p align="justify"><font face="Arial_12pt_st" size="12" color ...

'Call stream.WriteText({</td></tr></table>})

Call child1.SetContentFromText(stream, "text/html", ENC_NONE)

'Call child1.SetContentFromText(stream, "text/html", ENC_QUOTED_PRINTABLE)



Call stream.Truncate



' Bring the image into its entity (parent 2)

Set stream = session.CreateStream

If Not stream.Open(dataDir & "meapp2.gif", "binary") Then

	Msgbox "Could not open " & dataDir & "meapp2.gif", 16, "Open failed"

	Goto ExitSub

End If

If stream.Bytes = 0 Then

	Msgbox "File " & dataDir & "meapp2.gif" & " has no content", 16, "No Content"

	Goto ExitSub

End If

Call child2.SetContentFromBytes(stream, "image/gif", ENC_NONE)

Call child2.EncodeContent(ENC_BASE64)

Call stream.Close



' Prompt for the recipients

prompt = "Enter the recipients for this memo. Separate multiple values with a comma"

recipients = Inputbox(prompt, "Enter Recipients")

If recipients = "" Then

	Msgbox "You did not enter any recipients. Message not sent.", 16, "Not Sent"

Else

	Call doc.Send(False, Split(recipients, ","))

End If

ExitSub:

session.ConvertMime = True    ' Reset the value

Subject: Mime mail lotus script and images not visible in some web mailbox (eg: hotmail.com, libero.it …)

I don’t have a perfect solution, but I’m willing to share what I have. If you make improvements, please post them back to this thread.

Ok, here are 4 functions that you can add to your library.

The images show up in any Lotus Notes client, but not on the web (if you can fix the web limitation, that would be great). Anyway, this should get you a bit closer.

CODE START -----------------------------------------------------

Public Function DocGetMimeEntity(doc As NotesDocument, Byval itemName As String, Byval create As Boolean) As NotesMimeEntity

'/**

' * Retrieves a MIME Entity from a document.

' * @param doc The NotesDocument that contains the mime entity.

' * @parma itemName The name of the item used to store the mime entity.

' * @param create Specify True to create the entity if it does not already exist.

' * @return The specified mime entity.

' */



Dim sess As New NotesSession()

Dim entity As NotesMimeEntity

Dim bConvertMime As Boolean



' Init

bConvertMime = sess.ConvertMime

sess.ConvertMime = False



' Get existing mime entity.

itemName = Trim(itemName)

If (itemName = "") Then itemName = "Body"

Set entity = doc.GetMIMEEntity(itemName)



' Create new mime entity.

If (entity Is Nothing) Then

	If (create) Then

		If (doc.HasItem(itemName)) Then

			Call DocRemoveMimeEntity(doc, itemName)

		End If

		Set entity = doc.CreateMIMEEntity(itemName)

	End If

End If



' Return mime entity.

Set DocGetMimeEntity = entity

sess.ConvertMime = bConvertMime

End Function

Public Sub DocRemoveMimeEntity(doc As NotesDocument, Byval itemName As String)

'/**

' * Removes a mime entity from a document.

' * @param doc The NotesDocument that contains the mime entity.

' * @parma itemName The name of the item used to store the mime entity.

' */



Dim sess As New NotesSession()

Dim mimeEntity As NotesMIMEEntity

Dim mimeItem As NotesRichTextItem

Dim mimeItemType As Long

Dim bConvertMime As Boolean



' Init

bConvertMime = sess.ConvertMime

sess.ConvertMime = False



' Remove the MIME entity.

Set mimeEntity = DocGetMimeEntity(doc, itemName, False)

If (Not mimeEntity Is Nothing) Then Call mimeEntity.Remove()

Call doc.CloseMIMEEntities(True, itemName)



' Remove the NotesItem used to store the MIME.

If (doc.HasItem(itemName)) Then

	

	' If RichText, remove any embedded objects.

	Set mimeItem = doc.GetFirstItem(itemName)

	mimeItemType = mimeItem.Type

	If (mimeItemType = RICHTEXT) Then

		If (Isarray(mimeItem.EmbeddedObjects)) Then

			Forall obj In mimeItem.EmbeddedObjects

				Call obj.Remove()

			End Forall

		End If

	End If

	

	' Remove item.

	Call doc.RemoveItem(itemName)

	

	' If RichText, save document.

	If (mimeItemType = RICHTEXT) Then Call doc.Save(True, False)

	

End If



Call doc.RemoveItem(itemName & "MimeUpdated")



' Cleanup

sess.ConvertMime = bConvertMime

Call Destroy(mimeEntity)

Call Destroy(mimeItem)

End Sub

Public Sub DocSetMimeEntityHtml(doc As NotesDocument, Byval itemName As String, Byval html As String, imageFilePaths As Variant, imageContentIds As Variant)

'/**

' * Sets the html part of a mime entity.

' * Note: In-line images must be specified in the HTML code using an IMG tag.

' * For example, if the image's file path is "c:\temp\test.gif", the tag might be:  <img src="cid:test.gif">, 

' * the imageFilePaths array would contain ["c:\temp\test.gif"], and the imageContentIds array would contain ["test.gif"].

' * @param doc The NotesDocument that contains the mime entity.

' * @parma itemName The name of the item used to store the mime entity.

' * @param html A string containing the HTML code.

' * @param imageFilePaths An array of strings that contains the full path to all image files referenced by the HTML code.

' * @param imageContentIds An array of strings that contains the content id (cid) of all image files contained in imageFilePaths.

' */



Dim sess As New NotesSession()

Dim stream As NotesStream

Dim mimeBody As NotesMIMEEntity

Dim mimeHeader As NotesMimeHeader

Dim mimeHtml As NotesMIMEEntity

Dim mimeImageHeader As NotesMimeHeader

Dim mimeImage As NotesMIMEEntity

Dim item As NotesItem

Dim strImagePath As String

Dim strImageExt As String

Dim strImageCid As String

Dim strImageType As String

Dim iImageIndex As Integer

Dim bSetImages As Boolean

Dim bConvertMime As Boolean



' Init

bConvertMime = sess.ConvertMime

sess.ConvertMime = False

itemName = Trim(itemName)

If (itemName = "") Then itemName = "Body"

bSetImages = False

If (Isarray(imageFilePaths) Or Isarray(imageContentIds)) Then

	If (Ubound(imageFilePaths) <> Ubound(imageContentIds)) Then

		Error 2000, " The image file array does not match the image cid array."

	Else

		bSetImages = True

	End If

End If



' Create or replace the mime entity.

Call DocRemoveMimeEntity(doc, itemName)

Set mimeBody = DocGetMimeEntity(doc, itemName, True)



' Add the HTML part.

Set stream = sess.CreateStream()

Call stream.WriteText(html)

Set mimeHtml = mimeBody.CreateChildEntity()

Call mimeHtml.SetContentFromText(stream, {text/html; charset="iso-8859-1"}, ENC_QUOTED_PRINTABLE)

Call stream.Close()



' Add the image content.

If (bSetImages) Then

	For iImageIndex = 0 To Ubound(imageFilePaths)

		

		' Get the image file path and content id (cid).

		strImagePath = Trim(imageFilePaths(iImageIndex))

		If (strImagePath = "") Then Exit Sub

		strImageCid = Trim(imageContentIds(iImageIndex))

		If (strImageCid = "") Then Exit Sub

		

		' Get the image context type.

		If (Instr(1, strImagePath, ".") <> 0) Then strImageExt = Strrightback(strImagePath, ".") Else strImageExt = ""

		Select Case Lcase(strImageExt)

		Case "gif":	strImageType = "image/gif"

		Case "jpg":	strImageType = "image/jpg"

		Case Else:	strImageType = "image/gif"

		End Select

		

		' Add the image part.

		Set mimeImage = mimeBody.CreateChildEntity()

		Set mimeImageHeader = mimeImage.CreateHeader({Content-ID})

		Call mimeImageHeader.SetHeaderVal("<" & strImageCid & ">")

		Call stream.Open(strImagePath)

		Call mimeImage.SetContentFromBytes(stream, strImageType & {;name="} + strImageCid + {"}, ENC_IDENTITY_BINARY)

		Call stream.Close()

		

	Next

End If



' Clean up

sess.ConvertMime = bConvertMime

Call doc.CloseMIMEEntities(True, itemName)

Call doc.ReplaceItemValue(itemName & "MimeUpdated", Now)

Call Destroy(mimeImageHeader)

Call Destroy(mimeImage)

Call Destroy(mimeHtml)

Call Destroy(mimeHeader)

Call Destroy(mimeBody)

Call Destroy(stream)

End Sub

Public Sub Destroy(obj As Variant)

'/**

' * Deletes an object and sets its handle to Nothing

' * @param obj The object to destroy

' */



If (obj Is Nothing) Then Exit Sub

Delete obj

Set obj = Nothing

End Sub

CODE END --------------------------------------------------------

USAGE: Here is an example that will compose and send a simple html memo:

Sub TestMime()

Dim sess As New NotesSession()

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim html As String

Dim imageFilePaths(0) As String

Dim imageContentIds(0) As String



Set db = sess.CurrentDatabase



Set doc = db.CreateDocument()

doc.Form = "Memo"

doc.SendTo = "User Name/Mainline"

doc.Subject = "MIME IMAGE TEST #1"



html = |
This is a test!

<img src="cid:IMAGE1">

|

imageFilePaths(0) = "C:\Temp\some_image.gif"

imageContentIds(0) = "IMAGE1"

Call DocSetMimeEntityHtml(doc, "Body", html, imageFilePaths, imageContentIds)

Call doc.Send(False)

End Sub

Subject: RE: Mime mail lotus script and images not visible in some web mailbox (eg: hotmail.com, libero.it …)

Dear Bill Hanson,i wish to thank you for the response.

it is very late for my response, excuse me again…

i have not logged into this forum for more and more time.

i will try your suggestions and return to you a feedback.

By

Dadoo