OpenNTF.org - Send HTML mails from LotusScri
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Send HTML mails from LotusScript 
Rating:
Rating: 4.6 , Number of votes: 5 
Contributor:
Davy Vanherbergen 
Category:
Lotusscript 
Type:
API Functions 
Notes Version:
R5.x, R6.x 
Last Modified:
07 Jun 2004 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
This code calls the C-API from Lotusscript and lets you add a simplified item of type MIME to a document.

Perfect for sending HTML mails...

drawbacks:
- current implementation is limited to win32
- maximum html length supported is 32k (if you don't know how much this is, it's a string long enough to fill 2.5 pages of a MS Word document )

Usage / Example
Option Public
Use "SimpleMIME"

Sub Initialize

Dim s As New notessession
Dim db As notesdatabase
Dim doc As notesdocument
Dim html As String

Set db = s.currentdatabase
Set doc = db.createdocument

doc.form = "Memo"
doc.sendto = "Davy Vanherbergen"

html = |This <i>is</i> an <b>example</b><p>|
html = html + |<font color=purple>Hello</font><p>|

Call addMimeItem( doc, "Body", html )
Call doc.send(False)

End Sub
Code Attachments
SimpleMIME.lss (2 Kbytes)
 Comments
Posted by jian francis on 09/04/2003 12:51:20 AMHelp
Where do i place the code, in my html file?
Posted by Bruce Langner on 02/16/2004 09:17:33 PMYou Don't
You run it as an agent. In Domino.
Posted by Andy Seubert on 02/18/2004 10:08:36 AMHere is another way, more complex, more complete...
I have found the MIME stuff for making a more complete html email : Here is some code:
Function CreateAndSend (s As NotesSession,msg_text As String,msg_html As String,Recipient As String,Originator As String, Subject As String)
'## feed this function with
'## NotesSession
'## text for the text alternative to the HTML
'## the HTML as text
'## The email address of the recipient
'## the email address of who you want it to be "from"
'## the subject line as text
'## Create the email document
Set m_doc = db.CreateDocument()
s.ConvertMIME = False '## Do not convert MIME to rich text
Set stream = s.CreateStream
Set body = m_doc.CreateMIMEEntity
Set header = body.CreateHeader("Content-Type")
Call header.SetHeaderVal("multipart/alternative")
Set header = body.CreateHeader("Subject")
Call header.SetHeaderVal(Subject)
Set header = body.CreateHeader("To")
Call header.SetHeaderVal(Recipient)
Set child2 = body.CreateChildEntity
Call stream.WriteText(msg_text)
Call child2.SetContentFromText(stream,"text/plain;charset=iso-8859-1",ENC_NONE)
Call stream.Close
Set child3 = body.createchildEntity
Call stream.WriteText(msg_html)
Call child3.SetContentFromText(stream,"text/html;charset=iso-8859-1",ENC_NONE)
Call stream.Close
m_doc.Principal = Originator '## the spoofing
Call m_doc.Save(True, True)
s.ConvertMIME = True '## Restore conversion
sending:
m_doc.Send False
Sleep(1) '## to reduce the load on the server, it sleeps for one second between sendings
Exit Function
Works like a charm, although I had to include the sleep line so as to not kill the server....:(
--
Andy
Posted by Carie Shopbell on 06/22/2004 08:16:09 AMHTML Emails
I am currently testing out different ways to send HTML emails from Domino. I tried Davy's solution, which worked. I've tried Andy's solution but I am obviously missing some parts. Where does the CreateStream come from?
Thanks,
Carie Shopbell
Posted by Andy Seubert on 06/22/2004 12:59:36 PMYou need to declare stuff for the MIMEEntity things like:
# Email Mime Stuff #########
Dim body As NotesMIMEEntity
Dim header As Variant
Dim child3 As NotesMIMEEntity
Dim child2 As NotesMIMEEntity
Dim child1 As NotesMIMEEntity
Dim stream As NotesStream
Dim stream1 As NotesStream
'#########################
Posted by Carie Shopbell on 06/23/2004 09:59:46 AMAhhh, your solution is for R6 -- it makes sense now:-)
Thanks for your response. The client that I am doing this work for is still on R5. Davy's solution will work fine for me with a little tweaking on my part.
Posted by Andy Seubert on 06/23/2004 10:08:44 AMwould you mind posting your finished work?
Or at least the intent of your project?
Mine is for mass emailing Marketing letters for my company. They wanted to be able to send real HTML emails with text parts for clients who had text-only readers. I would be happy to post the whole agent if you like even though it is not very polished yet, it prompts for the files containing the HTML part, the TEXT only part, the recipient list, and an exclude names list and then it sends an email to each recipient in the recipient list checking the exclude list for each name....
--Andy
Posted by Carie Shopbell on 06/23/2004 10:51:43 AMSure, when I am done, I will post my code here.
My client is a University. When new students are admitted, they want to send out a "Welcome" email and they would like it in HTML format. Previously, it has been just a standard text email. I definitely have to talk with them about students who may have text-only email. I'm interested in seeing your entire solution, even though it will not help me with this client. Also, here is another solution that I found, that you may be interested in http://www.codestore.net/store.nsf/unid/EPSD-5EQPZA?OpenDocument. I was unable to use it for my client because they have relay restrictions on their SMTP server and basically it thought that the email generated from this solution was SPAM.
Posted by Carie Shopbell on 06/30/2004 10:50:14 AMRandom "!" showing up in my HTML emails
I'm using Davy's code above and am rec'g random "!" in my HTML emails. My total length of this string is only 3166 bytes, so I don't BELIEVE that it is a string length issue. Any ideas?
Posted by algo xiao on 07/03/2004 12:58:41 AMI found the answer why string length reduce
HI,Carie:
I found the answer why string length reduce .
It returns the number of characters in function of Len ,so you need to change your code for returned
bytes.
I suggest you modify codes of function "addMIMEitem" in SimpleMIME.lss .
There are 2 parts you must amend it:
1.)clength =Len(itemvalue) --- >clength =Lenb(itemvalue)
2.)fldheader.length = Len(itemvalue) ---> fldheader.length = Lenb(itemvalue)
Algo
Posted by Carie Shopbell on 07/07/2004 12:33:20 PMIt still didn't work:-(
Algo--
Thanks so much for your advice. I still get the same results though:-( Any other thoughts or ideas that you have would be appreciated.
Carie
Posted by Andy Seubert on 07/07/2004 01:12:28 PMIf the sending is already a manual operation, then
Why not just paste the web page in to the email by hand?
Other wise, I would highly recommend upgrading to R6...
Because your nnotes.dll my not be identical to Davy's resulting in odd errors like you describe.
Perhaps it is replacing characters with the "!" character though? You might check the output text against the input text to see where the "!" are occurring.
Another idea is to troubleshoot why the java solution on http://www.codestore.net/store.nsf/unid/EPSD-5EQPZA?OpenDocument generated errors...
If you are crafting the email by hand like that then you should be able to send the email through your domino server..
--AS
Posted by Luis Fernandez on 09/21/2004 01:43:18 AMImages in html mail
Hi all,
I■m using Davy■s solution and it works nearly perfect for me.
The trouble is that the message appears with images and formatted text in Outlook client, but when I read this same message in Notes client, I can only see the formatted text, but no the images.
In the HTML code of the message I have call the images like that: <IMG SRC="http://www.blablaba.com/image.jpg">
Anybody knows how to resolve this?
Thanks in advance.
Posted by Bruno CARTIGNY on 10/12/2004 04:08:56 PMAndy, would you mind posting your work?
Hi Any,
I've been asked from my developers for a mailing db able to send the HTML source of a Newsletter page (for better rendering than copy-paste in memo R6). Sound like the stuff you've done...
Is your work shareable on ONTF ?
Thanks in advance...
-- BC
Posted by Michael Kenney on 03/16/2005 04:09:38 PMAttachments
I've worked out the creation of MIME emails using lotusscript but I'm totally at a loss as to adding attachments. I need to be able to attach pdf and Word files. Does anyone have a working example they'd be willing to share?
Posted by Himani B Bhagat on 08/01/2007 05:16:27 AMError message "Cannot open included file SimpleMime"
Hello
I have used this code and run my agent every week. But this time an error is popping up saying "Cannot open included file SimpleMime". I dont understand why this happened. I always run this happened as I never changed my code or the file location
 Add your comment!