HTML emails via PassThruHTML... not as advertised

I’m programming in VB through an Access database trying to utilize the Lotus Notes COM object. What I’m trying to do is send HTML emails using the PassThruHTML property. Things aren’t working.

Here’s the sample code the documentation provides (WHICH DOES NOT WORK!)…

Sub Initialize

 Dim session As New NotesSession

 Dim db As NotesDatabase

 Set db = session.CurrentDatabase

 Dim doc As New NotesDocument(db)

 Call doc.AppendItemValue("From", session.UserName)

 Call doc.AppendItemValue("Subject", _

 "Meeting time changed")

 Dim richStyle As NotesRichTextStyle

 Set richStyle = session.CreateRichTextStyle

 Dim richText As New NotesRichTextItem(doc, "Body")

 richStyle.PassThruHTML = True

 Call richText.AppendStyle(richStyle)

 Call richText.AppendText("<B>Hello</B>")

 Call doc.Save(True, False)

End Sub

Anyway, I’ve seen some other posts suggesting to wrap my HTML code in brackets… that doesn’t work either.

Has anyone here come across this problem recently and found a solution? Anyone here ever successfully sent an HTML-formatted email from the Lotus Notes COM object???

I truly appreciate any help anyone could provide.

Thank you!

Subject: can’t set oStyle.PassThruHTML to True!!!

If you notice in my VB code, I have to set the PassThruHTML flag = 1. I get an error if I try and set it to True (like the documentation tells you to do).

I’m not sure that will affect anything seeing that 1 is usually interpreted as true, but I thought I’d toss it in there.

Subject: RE: can’t set oStyle.PassThruHTML to True!!!

I’m trying to do this same exact thing (sending HTML E-mail from Lotus Notes via vb.net), and I am finding the same problems you wrote about. Were you able to figure out a solution?

Thanks,

Joanna

Subject: HTML emails via PassThruHTML… not as advertised

Not entirely 100% sure of this but its worth a shot…

You may have to have your Notes Admin guy make sure the following setting is set for the server you are using …

In the Domino Admin Client under:

Messaging\Configuration

(MIME TAB\Conversion Options tab\Outbound tab)

make sure the following is selected:

Message content: from Notes to Plain Text and HTML

I think the default is set to “from Notes to Plain Text”. This setting should attempt to convert outgoing email to html…

hth,

Wendall

Subject: HTML emails via PassThruHTML… not as advertised

Let’s start with this simple truth: you can’t send HTML mail using passthru HTML in LotusSCript or COM. “HTML” mail uses MIME, with HTML as one of the MIME-part passengers in the MIME entity. If passthru HTML works when manually sent from the Notes client, it is because of high-fidelity CD-to-MIME conversion outbound (a result of selecting MIME as the format for mails addressed to internet addresses on the location document), and that requires the UI.

Take a look at NotesMIMEEntity.

Subject: (Solved!) HTML emails via PassThruHTML… not as advertised

Following Stan Rogers, I found this code. It is from http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/a2bb7f988f61ca6c852574c90056cce0?OpenDocument and it does work!

Sub Initialize

Dim s As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim body As NotesMIMEEntity

Dim header As NotesMIMEHeader

Dim stream As NotesStream

Set db = s.CurrentDatabase

Set stream = s.CreateStream

s.ConvertMIME = False ’ Do not convert MIME to rich text

Set doc = db.CreateDocument

Call doc.ReplaceItemValue(“Form”, “Memo”)

Set body = doc.CreateMIMEEntity

Set header = body.CreateHeader(“Subject”)

Call header.SetHeaderVal(“MIME message”)

Set header = body.CreateHeader(“To”)

Call header.SetHeaderVal(“john.doe@mydomain.com.br”) 'mail to recipient here

Call stream.WriteText({Click here for CNN})

Call body.SetContentFromText _

(stream, “text/plain;charset=UTF-8”, 1726)

Call doc.Send(False)

s.ConvertMIME = True ’ Restore conversion

End Sub

Subject: Is the code shown living in an Access db or a Notes db?

Subject: RE: Is the code shown living in an Access db or a Notes db?

It’s code in an Access database.

Subject: RE: Is the code shown living in an Access db or a Notes db?

That’s at least part of the problem. That code is legal in Notes but won’t work via COM, so you’re not even getting to the point of constructing the message. CurrentDatabase isn’t implemented for COM (the code is running outside of a Notes database, so there’s no current db), so you’ll have to explicitly name and open a database. Also, this line won’t work:

Dim doc As New NotesDocument(db)

You’ll need to dim doc as notesdocument, then later on set doc = db.createdocument.

Subject: You’ve got to modify your code

The code you’ve shown will only work when run in the Notes client. To do the same thing from Access (or Excel or whatever) some modifications are needed:

Dim s as New NotesSession

'…other Dim statement

set s = new NotesSession

'Now for the part that COM needs

s.initialize 'This should prompt for user.id password

set db = s.getDatabase(“SomeServer”, “xyz.nsf”)

set doc = db.CreateDocument()

'etc.

The rest of the code should be similar to your original post.

Subject: RE: You’ve got to modify your code

Sorry… let me clear up things a bit…

The code I posted is VB code. I indeed had to modify a bit to make it Access/VB friendly. I got everything working beautifully as far as plain-text emails are concerned… I can send those out like there’s no tomorrow.

To send the HTML emails, just like the documentation says, I set the PassThruHTML property to true and and appended my HTML text. Unfortunately, the text was interpreted literally thus showing all the tags in their full glory and no formatting whatsoever.

Sorry if my code caused confusion… but know that I’ve gotten the email fucntionality working great as far as plain-text emails go.

Thanks,

Ryan

Subject: *** here’s the actual code I’m running

The code snippet I posted earlier was from the Lotus Notes COM documentation.

Public Sub sendEmail(emailTo, emailCC, emailBCC, emailSubject, emailText)

'declare our various Notes variables

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim notedir As NotesDbDirectory

Dim rtitem As NotesRichTextItem

Dim session As New NotesSession

Dim link As Hyperlink 'not used (yet)



'initialize session with MY Notes password

session.Initialize "*****"



'a bunch of Notes formalities I don't care to understand

Set notedir = session.GetDbDirectory("")

Set db = notedir.OpenMailDatabase

Set doc = db.CreateDocument

Set rtitem = doc.CreateRichTextItem("Body")



'THIS IS A TEST

Dim rtstyle As NotesRichTextStyle

Set rtstyle = session.CreateRichTextStyle







'=======================

'THIS IS THE PART THAT DOESN'T WORK AT ALL

'-IT WON'T ACTUALLY FORMAT MY EMAILS IN HTML

'=======================

rtstyle.PassThruHTML = 1

    

'set email's text

With rtitem

    .AppendStyle rtstyle

    .AppendText emailText

    '.AddNewLine 2

End With



'put things back to normal

rtstyle.PassThruHTML = 0

rtitem.AppendStyle rtstyle



'set email's send/subject info

With doc

    .ReplaceItemValue "SendTo", emailTo

    .ReplaceItemValue "CopyTo", emailCC

    .ReplaceItemValue "BlindCopyTo", emailBCC

    .ReplaceItemValue "Subject", emailSubject

    .ReplaceItemValue "Form", "Memo" 'not sure what this is

End With





'SEND THE EMAIL!!!

doc.Send False





'kill 'em all

Set doc = Nothing

Set db = Nothing

Set session = Nothing

End Sub

Subject: RE: *** here’s the actual code I’m running

Ryan,

Have you tried enclosing your HTML text inside square brackets ?

Subject: RE: *** here’s the actual code I’m running

“Anyway, I’ve seen some other posts suggesting to wrap my HTML code in brackets… that doesn’t work either.”

Yup. :slight_smile:

*note: in the HTML snippets below, the message boards erased the first brackets in my code strings. weird.

I’ve tried “[ b>stuff]” and tried complete HTML strings like

“[ html>asdmore stuff]” to no

avail.

Have you ever successfully sent an HTML email from the COM object? If you have,

do you have any code you could share?

Subject: RE: *** here’s the actual code I’m running

Ryan,

Never did it through COM. Since I’m a Notes developer, I am typically working within that sphere of objects and don’t have to launch them externally.

Have you tried this via OLE?