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