Dec
13
Posted on 2005-12-13
Filed Under (LotusScript) by Johan Känngård

To send HTML mails in R6, you have to use the setContentFromText method in the NotesMIMEEntity class. To add inline images, use the setContentFromBytes method in the same class, like this:

Dim session as New NotesSession()
session.convertMIME = False ' Do not convert to rich text
Dim currentDb As NotesDatabase
Set currentDb = session.currentDatabase
Dim path As String
path = "c:\temp\test.html"
Dim message As NotesDocument
Set message = currentDb.createDocument()
Call message.replaceItemValue("Form", "memo")
Call message.replaceItemValue("From", "your@email.com")
Call message.replaceItemValue("Subject", _
"HTML email via MIME")
Call message.replaceItemValue("SendTo", "another@email.com")
Dim body As NotesMIMEEntity
Set body = message.CreateMIMEEntity
Dim mh As NotesMimeHeader
Set mh = body.CreateHeader({MIME-Version})
Call mh.SetHeaderVal("1.0")
Set mh = body.CreateHeader("Content-Type")
Call mh.SetHeaderValAndParams( _
{multipart/related;boundary="=NextPart_="})
Dim mc As NotesMIMEEntity
Set mc = body.createChildEntity()
Dim stream As NotesStream
Set stream = session.createStream()
If Not stream.open(path, "ISO-8859-1") Then
Error 2000, "Could not open file"
End If
Call mc.setContentFromText(stream, _
{text/html;charset="iso-8859-1"}, ENC_NONE)
Call stream.close()
Call addImage(body, "C:\temp\image1.gif")
Call addImage(body, "C:\temp\image2.gif")
Call message.send(False)


The addImage method looks like this:

Public Sub addImage(body As NotesMimeEntity, _
imagePath As String)
Dim id As String
Dim stream As NotesStream
Dim mh As NotesMimeHeader
Dim mc As NotesMIMEEntity
id = Strrightback(imagePath, "\")
Set stream = session.createStream()
Set mc = body.createChildEntity()
Set mh = mc.createHeader({Content-ID})
Call mh.setHeaderVal(id)
Call stream.open(imagePath)
Call mc.setContentFromBytes(stream, _
"image/gif;name=""" + id + """", ENC_IDENTITY_BINARY)
Call stream.close
End Sub

The HTML code must refer to the images via URL:s containing cid and the “path” to the image, like this:

<img src="cid:imagename.gif" />

Found this great tip via LDD, posted by Raymond Neeves.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
(16) Comments    Read More   

Comments

Jeff Crossett on 15 December, 2005 at 02:35:21 #

Very cool. I Did something similar in sending a Notes e-mail from an XML call.

http://www.crossedconnections.org/w/?p=45


Johan Känngård on 16 December, 2005 at 00:32:50 #

Nice!


Jason on 22 December, 2005 at 05:34:21 #

Dear Sir, I can’t use your scripts since there are some errors below, and I’m unable to find any information from Notes help, my version is R5.0.13 could you give me some help? Thanks.

Dim mh As NotesMimeHeader
Set mh = body.CreateHeader({MIME-Version})
Call mh.SetHeaderVal(“1.0″)
Set mh = body.CreateHeader(“Content-Type”)
Call mh.SetHeaderValAndParams( _
{multipart/related;boundary=”=NextPart_=”})


Johan Känngård on 22 December, 2005 at 11:26:57 #

Jason, it only works in R6 and above.


Cristian D'Aloisio on 5 January, 2006 at 17:19:06 #

After some tests with Gmail account and Thunderbird mail client, I had to update AddImage() sub because the value for “Content-ID” header must be enclosed with chars.

Call mh.setHeaderVal(“”)

Bye
CD


Cristian D'Aloisio on 5 January, 2006 at 17:24:05 #

previous post was bad-translated!

“less than” symbol & id & “greater then” symbol

Call mh.setHeaderVal(“<” & id & “>”)


Hardeep Singh on 13 April, 2006 at 11:17:02 #

Hi,

I am a MCA graduate and came accross Lotus Notes as part of my academic project at M/s. Tata Steel,India. I found it quite interesting and want to specialize in this field.

But I cant find any helpful books on Lotus Script that will help me built my foundation on the topic.

I would be very grateful if you please let me know any ebooks or related sites that helps the beginers.

In internet lots of help is available but they are either above my level or in chunks of examples. I need to build a foundation now.

Looking forward to your response.

My mail id’s is

hardeep203@gmail.com
explore203@gmail.com

Thanking you.

Hardeep Singh
India


Johan Känngård on 16 April, 2006 at 18:59:32 #

Try searching on Amazon.com with the keyword LotusScript. There are several books that may be of interest!


ankit mantri on 19 February, 2008 at 16:27:27 #

how can i use STRRightBack method in lotusscript. I dont know the proper syntax. can anybody send me a small working example


Johan Känngård on 19 February, 2008 at 16:57:45 #

It finds the “right-most” part of a string starting from the “right-most” second argument, so StrRightBack(“Johan Is Back”, ” “) gives you “Back”.
Look at:
https://qp.research.ibm.com/help/help7_designer.nsf/f4b82fbb75e942a6852566ac0037f284/e1f903a7f19c9d5e8525704a00405c7b?OpenDocument


Rubem Rocha on 10 March, 2008 at 17:37:20 #

Mr. Johan, I’ve tried to use this tip, but the format information the HTML content I’d like to send is not respected (font size, for example!). What can I do to fix this? Thx!


Johan Känngård on 10 March, 2008 at 17:51:43 #

What is the problem and how do the HTML look like?


Raul on 9 April, 2008 at 09:18:32 #

Mr Johan, I am trying to send an email using Lotusscript. This script reads values from two rich text fields, composes an email and appends the rich text field values in mail body. The problem is that the mail always goes as Text and any colored text from rich text field is not coming in same format in mail body. Can you suggest some thing?


Steve Marshall on 10 April, 2008 at 20:32:40 #

I’m trying to use StrRightBack to display the contents of a string appearing next to a “-”. The code I’m using is:

Call doc.ReplaceItemValue( “FeaturedBlog_Title”, Strrightback(blogDoc.Categories, “-”))

I don’t get an error when I save the document, but I get a type mismatch in the client. Categories is a text field. Can you help?

Thanks,

Steve


Johan Känngård on 11 April, 2008 at 01:01:31 #

You must do something like:
Call doc.ReplaceItemValue( “FeaturedBlog_Title”, Strrightback(blogDoc.Categories(0), “-”))


Nicola Karkanis on 18 December, 2008 at 14:25:53 #

very nice script


Post a Comment
Name:
Email:
Website:
Comments: