logo

Sending HTML mail via SMTP part 3

In the last article I showed all the code required to send a mail in HTML format. All very well but it's not what we really want to actually start using in our applications. What we want is a more powerful way of using the code in the agent. Wouldn't it be nice if we could simply supply any URL and the agent uses this as the source of the HTML for the mail. Well we can. This means that we can use the power of Domino forms and views to build the HTML and then send this in the mail. It doesn't have to be a Domino URL - we can use any location as long as the server has access to read form it.

Another change I've made to the sample database is to add a scheduled agent. We can now create documents in the database from any other database and wait for the agent to do the sending for us. This approach means that the Mail Database is a central location for sending formatted mail from all our applications.


Sending mail from any URL:

The code in the last article to send a message was simply:


msg.sendMessage( sFromTrue, sFromShow, vToTrue, sToShow, sSubject, vBody );

The only change required to send the HTML from a URL is:

msg.sendMessage( sFromTrue, sFromShow, vToTrue, sToShow, sSubject, vURL );

Notice that the last parameter has changed. In the first we sent a Vector object containing each line of the HTML. In the second we send a URL object. The actual code in the Java Script Library has two methods with the same name - "sendMessage". Java knows which one to use depending on the type of the arguments passed to it. This is known as Overloading and is very useful in circumstances like these.

So, in our agent that calls the sendMessage method, we need a line of code like the following to build a URL object:

URL vURL = new URL ( vNotesDocument.getItemValueString("URL") );

Then in the code that builds the mail we can use this to open an inputstream and loop through each line of the source and write it to the mail. The code for this is simpler than you might expect:

String inputLine;
BufferedReader in = new BufferedReader( new InputStreamReader( vURL.openStream( ) ) );

while ( ( inputLine = in.readLine( ) ) != null ) {
 sendText ( inputLine );
}
in.close();

As an example I used the agent to send all the HTML from the URL of the view called "URLs" in the sample database. Here's what it looks like in the browser:

image


Somewhat surprisingly, this doesn't look all that different when the client reading the mail happens to be Notes. Note however that is has ignored the stylesheet and the background logo image. Apart from that is laid out as we'd expect and all the links work.

image


As I mentioned in part 2 of this article, the Outlook client is a lot more reliable as it actually uses Internet Explorer to render the content of the mail. As you can see in the shot below it looks exactly the same as in the browser. In fact the only difference is that the Outlook preview-pane doesn't allow any JavaScript. That means anything like window.open and document.write is useless. Worth keeping in mind.

image


Hope this is enough to convince you of how powerful an application this can be. Using forms and views there is almost no limit to the content and format of the pages that you send. Just imagine how impressed the boss will be when they get a mail listing the latest content on the intranet, all nicely formatted with corporate logos and colours.

Sending mail from other applications:

To make this in to a truly useful application we need the ability to use it from all our other applications. To do this I've added a third form called "SendAUT". This has all the fields required to use either the URL or HTML methods. Using the following LotusScript we can create a document in the HTML Mail database from anywhere else and then wait for the agent to pick it up when it's next due to run.

Dim vDocSession As NotesSession
Dim vDocDatabase As NotesDatabase
Dim vMailDatabase As New NotesDatabase ("", "")

Call vMailDatabase.Open( "epsdomsvr01", "apps/htmlmail12.nsf" )

if ( Not vMailDatabase Is Nothing ) Then
Set vMailDocument = vMailDatabase.CreateDocument
vMailDocument.Form = "SendAUT"
vMailDocument.From = "jhowlett@EITS"
vMailDocument.FromShow = "Jake Howlett <jhowlett@EITS>"
vMailDocument.SendTo = "developerone@EITS,developertwo@EITS"
vMailDocument.ToShow = "All Developers <$developers@EITS>"
vMailDocument.Subject = "Homepage as been updated. Here is a copy.."
vMailDocument.URL = "http://www.codestore.net/A55692/store.nsf"
vMailDocument.ComputeWithForm

vMailDocument.Save True, True
End If

When the agent opens this document it knows that it needs to use the overloaded method that sends a URL as the final paramater because there is a value in the field called "URL". If you wanted to use the method of adding all the HTML to the mail yourself then, instead of adding a value to the "URL" field, you add all the HTML, line by line, the field called "Body":

Dim vBodyItem As NotesItem
Set vBodyItem = vMailDocument.GetFirstItem( "Body" )
Call item.AppendToTextList( "<html>" )
Call item.AppendToTextList( "<body>" )
Call item.AppendToTextList( "<h1>" )
Call item.AppendToTextList( "hello in big letters" )
Call item.AppendToTextList( "</h1>" )
Call item.AppendToTextList( "</body>" )
Call item.AppendToTextList( "</html>" )

This adds lines of HTML to the item called "Body" which is of type multi-value. This is then passed in to the method as the vector object that we saw earlier.

Room for improvement:

What would be nice when you add a document from another application is to be kept updated as to when and if it is sent. Errors can occur while trying to send mails and it would be useful to have a set number of retries at sending it before somebody is made aware of its failure.

As I mentioned in the first article in this series we have to use valid SMTP addresses when sending the mail. Getting hold of these is fairly easy if the user enters a Domino user name and you get the code to find their short name and domain combination. This won't work in a mixed environment of Exchange and Domino though. The ideal solution is to use LDAP to find the SMTP address of any given name.

Any ideas or requests that you might have - let me know...

Noteworthy:

Something worth noting is that the way this works can be dictated by the server on which the agent runs. If the server doesn't have access outside the firewall then you will have problems specifying internet addresses in the URL field.

If the server tries to open a page that it doesn't have access to and an error message is returned then this is what will get mailed to the recipients. Not nice. Worth checking this first.

<<< Part 1
<<< Part 2
Part 3

Feedback

  1. Cool as usual....

    Jake,

    You always impress us... what a beautiful piece of article..... If just a half of the "technical writers" write the way you do......

    Keep the good work...

    Alex alex@dominocode.net

    1. Re: Cool as usual....

      Cheers Alex,

      I hope what I wrote in the blog today didn't seem as though I was fishing for this kind of comment ;o)

      Whether feedback is good or bad it's always good to get some so that I at least no people are reading what I write. Otherwise I don't know if it's all a waste of time or not.

      Glad you liked it!

      Jake -codestore

      Show the rest of this thread

  2. this is cool

    Thanks Jake, this type of article makes it easier for the rest of us, great work.

    I think Alex has made a good point, you do write excellent technical articles, ever thought of writing an advanced domino developer book ????

    i'm sure there are plenty of us who would help in any way we could, it's the least we could do ;-)

    cheers

    mark

    1. Re: this is cool

      Cheers Mark,

      I have actually thought about a book. The main thing that stops me is time. This site would suffer as a consequence. The only reason to write a book (other than fame and the resumé) is to make money. That's something that's never really bothered me that much. Why write a book when I can do it all here and you guys don't need to pay ;o)

      The mistake I made was to tell my dad that I had thought about it. Now every time I see him it's "How's the book coming along Jake?". His interest being that he could say "Look what our Jake's done!".

      Jake -codestore

      Show the rest of this thread

  3. Good One

    I came across your article and the site today .. Must say you have built a very impressive and clean site. Keep up the good work !!

  4. Cheers Jake

    Jake, many thanks for your articles and for making codestore.net available to us.

    I find many of your articles extremely helpful and enlightening.

    I've been developing Notes apps for 2 and a half years now and been doing Domino stuff for 9 months. As we all know, there aren't many decent Domino-related sites out there, so all the help is very much appreciated.

    I've installed the NewzCrawler application and have RSS feeds from both codestore.net and notestips.com to keep up to date with articles.

    Thanks again Jake, Keep up the excellent work.

    -Ashik

    • avatar
    • Kurt
    • Wed 17 Apr 2002

    network folder as URL

    Hi Jake,

    Really magnifical ! And we are not at the end yet with this Mail application !

    When you supply a folder link to a folder on your network, you receive an overview of the documents in that folder (why not receive a daily overview of a particular folder ) : example of the url (for the clip-art folder):

    file:\\yourservername\clip-art

    1. Brilliant

      Got to admit that I hadn't even thought of trying this.

      Not sure how best to make use of it but there must be a solution begging for this...

      Glad to see somebody using the app. Cheers Kurt!

      Jake

      Show the rest of this thread

      • avatar
      • Noel Hendrikx
      • Thu 18 Apr 2002

      Re: network folder as URL

      Did you know you can also launch Notes applications from a website?

      <a href="file:///c:/data/notes5/names.nsf">Open Personal NAB</a>

      Show the rest of this thread

    • avatar
    • Tom
    • Thu 18 Apr 2002

    Amazing }:o)

    It's been around 2 years I was trying to find an easy way to do that , and as I am no java developer I never figured out before this could be that good , thank you again , your site worth a lot for me :)

    ty

  5. Sending HTML mail via SMTP part 3 - Comments

    Hello,

    Thanks a lot for this tool; this is what I was trying to find and I though it was impossible!!!

    Only one question,

    Could I compose a document and send it without saving. I mean, what I'm doing now with lotus script is create a summary from several documents and including this summary in a normal memo (I compose the memo with the "RenderToRTItem" method in Lotus Script to add the content of a Notes document in a Rich Text Field), and then send the memo to the recipient without saving.

    Now, I know how to send an already saved notes document using the URL, but could I send a notesdocument without saving?

    Thank you very much

    1. Re: Sending HTML mail via SMTP part 3 - Comments

      Unfortunately not. The agent you need to run is in Java so you need to create a document that acts as the middle-ground between the two. What you can do is have the Java agent that processes this queue of mails delete them after they are sent.

      Alternatively, port the code you have already in LotusScript to Java. You can then use the classes in my agents directly.

      Jake -codestore

    2. Re: Sending HTML mail via SMTP part 3 - Comments

      hi , could u send me mail for sending mail through SMTP protocol and FOR receving THROUGH POP3 protocol plzzzzzzzzz

  6. Making sure it got there...

    This is an easy trick, and I'm sure that I'm not the only one to think of it. However, it is so handy, that I thought I'd share.

    We've got many applications that send automatic e-mails. Some are Java, some LotusScript, etc. We were having problems with these messages not going through (delivery failures) and no one getting notified. This was especially true when the e-mail came from the server.

    Our first solution was set the from field (using Principal for LS) to a real e-mail address, so that delivery failure notifications were delivered to a real person. This wasn't the best solution as the person would eventually quit or worse yet, be inundated by messages that they didn't care about and ignore them.

    The second solution was to create a mail-in database for webmaster@domain.com. We then made sure that all automated mail came from webmaster@domain.com. Then we added one line to the bottom of each message. Program Name: x.nsf. An hourly agent parses through the body of each message and searches for this string and sets a hidden field with the program name. Then, a view is set up that shows all messages categorized by program name and then categorized by message type (delivery failure, reply, etc).

    Now when I'm on-call, I can monitor only the mail that comes back from my team?s programs and ignore the others.

    A nightly agent cleans up mail that is over a week old so that the database doesn't fill up.

  7. Amgr Freeze with SendQueue

    I tried to run many ways including manually , can't get the agent to run at all it freeze my Amgr , the rest works smooth and nice (great job)

      • avatar
      • Patrick Ryan
      • Wed 29 May 2002

      Re: Amgr Freeze with SendQueue

      See [<a href="all/B8EB46D00F48EF8186256BC8003B1238">David Goodchild's response</a>] below.

  8. Good job, but SentAUT don't run in my server ...

    Domino 5.0.8 (spanish) - WinNT 4 (sp5)

    Great agent, Jake. I can send mail with SendMSG and SendURL forms, but not with SendAUT. SendQueue agent is running, but it not send messages. Any ideas?

    1. Re: Good job, but SentAUT don't run in my server ...

      The reason for the scheduled agent not working is the if statement - the string Object needs an equals or compareTo to test equality rather than ==. So:

      (vNotesDocument.getItemValueString("Status").equals("0") )

      should return true.

      Otherwise great App! Has saved me alot of time and headache after some rash promises....keep them coming!

      Show the rest of this thread

  9. One of the RCPT addresses was invalid?

    Hi everyone!

    Firstly let me say a huuuuge thanks to Jake. This site is my development BIBLE. (Please dont weird out im not a nut).

    My problem is with sending the HTML mail to external domains. Heres a bit of background. Id appreciate any comments.

    My company currently uses Exchange for email (Domino lost on that battlefront) and our Domino servers can post mail directly to the SMTP server.

    Mail is usually generated by LS agents and all deliver without any troubles. The Java agent in this demo worked fine while I was testing and incorporating the forms into one of our web apps, but when it came to do some "real world" testing I kept receiving the "One of the RCPT addresses was invalid?" error message.

    During initial testing I used my work email address as a default value (dlowden@acp.com.au) and all appeared fine - I was happily receiving full colour HTML glorified emails from Domino. But (and theres always a But isnt there) I decided to throw in a Hotmail curve ball for the hell of it and up pops the error message.

    Im sure its a Domino/Exchange thing but our Admin guys are mainly MS oriented. The thing that throws me is that LS mail can send thru OK.

    Any Help? Please?

    1. Re: One of the RCPT addresses was invalid?

      Hmmm, sounds like admin to me mate ;o)

      No idea what's going on here. The trouble with this "solution" is that each implementation is going to be completely different and each with its own problems and nuances.

      The solution I created initiallaly was also for an Exchange mail environment with Domino for web-apps. The only way I found to get it to work as expected was to get the Notes server to connect to the SMTP socket [<i>on the Exchange server</i>]. This way you should find that it all behaves as it would if you were sending a mail normally from Outlook or whatever. Using the Notes/Exchange Gateway seemed flawed to me.

      If you still have problems try sending mail to multiple recipients one at a time.

      Either way be sure to let us all know what you find....

      Jake -codestore

      Show the rest of this thread

  10. Very Good, but can't see HTML in notes

    Hello Jake, It is a great article. I use Outlook and Notes as Email system, and I receive the mail with the right html content in outlook, but in notes still an attachment c.htm containing the HTML. How do you setup to see it in html ? Thank you very much Rui Felipe

  11. connection refused

    First of all, I found this site by luck and it's great !

    Now for the problem: Copied your test database and set the host-value to hostname.domain.com. Signed the agent and created a document for the queue. Now, when I run the agent it does not send the mail, it generates a Connection refused entry in the mail's log and (for some reason not every time) on the server console visibly.

    Access rights are set to allow java agents, SMTP listener is on...

    Any suggestions ?

  12. How to add attachement for TEXT based Mail Clients

    wow... !! nice piece of work..

    I really appreciate this code.... and you get tons of new visitors/fans.. from our office.

    but can you help me with this, some of our users have TEXT based HTML clients.. and if they receive the HTML Mail, it appears as blank. How can we attach a Test file for NON HTML mail clients.

    -rupam

    • avatar
    • Jeff
    • Fri 21 Jun 2002

    Cc and Bcc functions

    Excellent db, but with Cc or Bcc functions will be great.

    1. Re: Cc and Bcc functions

      So why don't you just add them then:

      RCPT CC: me@privacy.net\r\n; RCPT BCC: spam.sucker@sendmespam.foo\r\n;

      Jake

    2. Re: Cc and Bcc functions

      Jake - just want to say THANKS!!! this is an awesome solution. Couple of questions though.

      I can't seem to get multiple RCPT TO addresses to work nor can I get the RCPT CC to work. I had this code modified to process to addresses from an array and process a CC address and it would work - kept saying all addresses not formatted correctly:

      Forall stos In SendTo ret = sendData(sock, "RCPT TO:" & stos & Chr(13) & Chr(10)) End Forall ret = sendData(sock, "RCPT CC:" & CopyTo & Chr(13) & Chr(10)) ret = isSockReady(sock) ret = receiveData(sock, myBuf) Print |<br>| & Left(myBuf, ret)

      What am I doing wrong???

      Many Thanks!!!!!

    • avatar
    • Anders Åbjörn
    • Wed 18 Sep 2002

    HTML Via SMTP can be done in lotusscript...

    ...if your server runs in a win32 environment it's quite easy to write an agent that sends mail via SMTP and thus enabling you to format your mail in any MIME format you choose including text/html.

    All you need is a little knowledge about winsock (wsock32.dll) and of course the SMTP protocol (RFC 821).

    If anyone is interested I've written an .LSS that takes care of the "messy" parts.

    1. Re: HTML Via SMTP can be done in lotusscript...

      Anders, How can we get a copy of the .lss you wrote?

      Many thanks, Coni Loving

      Show the rest of this thread

      • avatar
      • CNR
      • Thu 18 Dec 2003

      Re: HTML Via SMTP can be done in lotusscript...

      Hi, I've just found your articles and it was very helpfull for me to solve my problem.

      My question is about the reverse side of this topic . If i receive a message with an HTML content in the body field . Is it possible to extract it as an HTML file ?

      Thanks a lot for your response. Charlie

  13. SendQueue Agent modified

    Hello A great thank to you. I'm not sure you to get the last version because I had to change two things on my (5.08 Notes french client) in the SendQueue Agent :

    1/ if (vNotesDocument.getItemValueString("Status")== "0") never true, changed to : if (vNotesDocument.getItemValueString("Status").equalsIgnoreCase("O"))

    2/Put the last line out of try block which itself is contained in last mentioned if block. This one after a brace after : vNotesDocument = vNotesView.getNextDocument(vNotesDocument); Hope it'll help other java's newbies.

  14. shared server

    Works well on my personal server with enabled SMTP, but the public server I use does not permit to communicated with port 25. I intended to use SendURL form for my purpose (forwarding a complete page to an email address a visitor would enter, or a confirmation after completing a form). Any suggestion on how to work around this issue?

  15. SMTP error

    The following error persists: "A security exception has occurred"

    SMTP listener is enabled. Agent is signed. Any suggestions, anybody:)

    1. Re: SMTP error

      hi, jan, or jake,

      jake your website is such a gem... most the problems i encounter i find the solutions through you site. when i read your HTML email article six months ago, it worked beautifully and showed it to all my colleagues. i kept a version of that six month old test database which still runs perfectly.

      of late, i ran into the same problem as jan. now, that i try to use the concept of extracting HTML email from notes site, i made another copy of your SMTP socket mailer database on the same server where the old copy still runs perfectly. however, after recompiled agent WQS-SendURL on the news databse i get "security error".

      i placed a copy of the NSF on R6, which has

      http -ON enable lister -ON smtp mail routing -ON enable restricted java, unrestricted java - ON

      plus the agents, signed.

      still i got security error. Just to isolate the problem, i tried connecting and sending a 4 liner html throught the SMTP server using lotuscript and still works okay. in the same manner the old copy compiled six months ago is working fine.

      So, i think it has to do with the java mail class.

      I think it's more like Security Exception.

      I'm not a lotus notes server admin, i just do codes. What should i tell my admin colleague? which services on domino should she turn on?

      sorry for bothering you about this. and thank you very much, tina

  16. SEND HTML WITH LOTUS WITHOUT TOUCHING THE SERVER

    Hello Here !

    The problem I had was that I could not even touch to the domino server ( not even look at it , must be precious), therefore i was stuck ,when suddenly ... ... I decided to use the good old clipboard object to make my deal. It means that this is(again) a window only solution ( even if i think that the problem can be solved thisd way in with any OS)

    Pasting HTML into lotus limitations:

    I still must warn you to be very careful with your spanning, as the lotus browser is a bitch. Be also careful with nested tables as the browser will produce a huge linejump between your 2 nested tables. Other problem is the table border. Well, you've got the border, but i did not find a way to make it other thant standard white. Regarding embeding graphx , no sé yet ( if you have acces to the server or can get a long term lasting ftp directory, I would advice you to make a src pointing to your image, it works well. Lotus accepts Css , but doesn't seem to like Css for tables.

    Anyway, here is the way code (VB/lostusScript):

    First . add a reference to the LotusDominoObject library

    Then the following code is the code you need to send an email

    ----------------------------------------------------

    'declare your mail object Public newLotusMail As New cLotusMailClient.cLotusMail

    Private Sub LotusMailing()

    Call newLotusMail.Initialize(YourPassword, YourNotesDatabase, DominoServer)

    If newLotusMail.SendHtml(YourHTMLString,To,Subject,[CC],[Bcc]) = True Then

    msgBox"YooHoo,Your email has been sent. Have a break and go to your favourite record dealer and maybe get the last godspeed in vynil" ' just to verify it went ok

    end if

    End Sub -------------------------------------------------------------------------------- ------------

    '------------------------------------------- ' 2002 Ben Levy - Long life to Open source ! '-------------------------------------------

    Put the following code on a class called 'cLotusMailClient' Or do whatever you want with it

    Option Explicit

    Private pstrPassword As String Private pstrServer As String Private pstrMailDb As String

    Private oLotusSession As Object Private oLotusWorkspace As Object Private oLotusUIDoc As Object

    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function RegisterClipboardFormat Lib "user32" Alias _ "RegisterClipboardFormatA" (ByVal lpString As String) As Long Private Declare Function EmptyClipboard Lib "user32" () As Long Private Declare Function CloseClipboard Lib "user32" () As Long Private Declare Function SetClipboardData Lib "user32" ( _ ByVal wFormat As Long, ByVal hMem As Long) As Long Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _ ByVal dwBytes As Long) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _ ByVal Destination As Long, Source As Any, ByVal Length As Long) Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Function GlobalFree Lib "kernel32" ( _ ByVal hMem As Long) As Long

    Private Const GMEM_DDESHARE = &H2000 Private Const GMEM_MOVEABLE = &H2

    ________________________________________________________________________________ _____________

    '------------------------------------------- ' Gets the properties required to connect ' Session and database '------------------------------------------- Public Sub Initialize(ByRef strpassword As String, _ ByRef strMailDb As String, _ Optional ByRef strServer As String)

    On Error GoTo err:

    pstrPassword = strpassword pstrServer = strServer pstrMailDb = strMailDb

    If oLotusSession Is Nothing Then Set oLotusSession = CreateObject("Lotus.NotesSession") Call oLotusSession.Initialize(pstrPassword) Set oLotusWorkspace = CreateObject("Notes.NotesUIWorkspace") End If

    Exit Sub

    err: MsgBox "Problem in the InitializeDomino, Session not Initialized", vbCritical + vbOKOnly, "ERROR" End Sub

    ________________________________________________________________________________ ____________________

    '--------------------------- ' sends an html based email '--------------------------- Public Function SendHtml(ByVal strHTML As String, _ ByVal strTo As String, _ ByVal strSubject As String, _ Optional ByVal strCc As String, _ Optional ByVal strBcc As String) As Boolean

    strHTML = ClipboardFormatHTML(strHTML) PasteToClipboard (strHTML) SendHtml = SendMail(strTo, strSubject, True, , strCc, strBcc)

    End Function

    ________________________________________________________________________________ _________

    ' ---------------------------------------- ' Builds HTML Clipboard Header ' In order to be able to copy ' HTML to clipboard ' ---------------------------------------- Private Function ClipboardFormatHTML(ByVal strHTML As String) As String

    Dim strHeader As String ' Temp Header String Dim strRealHeader As String ' Final Header String Dim strBuildXmlTemp As String ' Temp Header String + Former HTML string

    strHeader = "Version:1.0" & vbCrLf strHeader = strHeader & "StartHTML:" & InStr(1, strHTML, "<HTML") & "00" & vbCrLf strHeader = strHeader & "EndHTML:" & Len(strHTML) - 4 & vbCrLf strHeader = strHeader & "StartFragment:" & InStr(1, strHTML, "<BODY>") + 8 & "00" & vbCrLf strHeader = strHeader & "EndFragment:" & Len(strHTML) - 36 & vbCrLf strHeader = strHeader & "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>" & vbCrLf strBuildXmlTemp = strHeader & strHTML

    strRealHeader = "Version:1.0" & vbCrLf strRealHeader = strRealHeader & "StartHTML: 000 " & vbCrLf strRealHeader = strRealHeader & "EndHTML:" & Len(strBuildXmlTemp) - 4 & vbCrLf strRealHeader = strRealHeader & "StartFragment:" & InStr(1, strBuildXmlTemp, "<BODY>") + 8 & vbCrLf strRealHeader = strRealHeader & "EndFragment:" & Len(strBuildXmlTemp) - 36 & vbCrLf strRealHeader = strRealHeader & "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>" & vbCrLf ClipboardFormatHTML = strRealHeader & strHTML

    End Function

    ________________________________________________________________________________ _________

    '------------------------------ ' Routine to Copy the HTML ' string to the clipboard '------------------------------ Private Sub PasteToClipboard(ByVal pstrHtmlString As String)

    Dim lngSuccess As Long Dim lngHTML As Long Dim lngGlobal As Long Dim lngpString As Long

    lngSuccess = OpenClipboard(frmMain2.hwnd) lngHTML = RegisterClipboardFormat("HTML format") lngSuccess = EmptyClipboard lngGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(pstrHtmlString)) lngpString = GlobalLock(lngGlobal) CopyMemory lngpString, ByVal pstrHtmlString, Len(pstrHtmlString) GlobalUnlock lngGlobal SetClipboardData lngHTML, lngGlobal CloseClipboard GlobalFree lngGlobal

    End Sub

    ________________________________________________________________________________ ____________

    '------------------------------------------ ' Creates a new memo from scratch ' saves it in the database ' sends the memo '------------------------------------------ Private Function SendMail(ByVal strTo As String, _ ByVal strSubject As String, _ ByVal booPaste As Boolean, _ Optional strBody As String, _ Optional ByVal strCc As String, _ Optional ByVal strBcc As String) As Boolean

    On Error GoTo err

    If oLotusUIDoc Is Nothing Then Set oLotusUIDoc = oLotusWorkspace.COMPOSEDOCUMENT(pstrServer, pstrMailDb, "Memo") End If

    Set oLotusUIDoc = oLotusWorkspace.CURRENTDOCUMENT

    'fill madatory mail fields Call oLotusUIDoc.FIELDSETTEXT("EnterSendTo", strTo) Call oLotusUIDoc.FIELDSETTEXT("Subject", strSubject)

    'Call oLotusUIDoc.CreateObject("bob", "HTML", "c:\test.html")

    'fill optional mail fields If strCc <> "" Then Call oLotusUIDoc.FIELDSETTEXT("EnterCopyTo", strCc) End If If strBcc <> "" Then Call oLotusUIDoc.FIELDSETTEXT("EnterBlindCopyTo", strBcc) End If

    If strBody <> "" Then ' fill the body if not html email Call oLotusUIDoc.FIELDSETTEXT("Body", strBody) ElseIf booPaste = True Then 'paste html to body Call oLotusUIDoc.GOTOFIELD("Body") Call oLotusUIDoc.Paste End If

    'send email and close

    Call oLotusUIDoc.Send Call oLotusUIDoc.Close

    SendMail = True

    Set oLotusUIDoc = Nothing

    Exit Function

    err:

    SendMail = False MsgBox "Problem in the SendMail Function, Email not sent", vbCritical + vbOKOnly, "ERROR"

    End Function ________________________________________________________________________________ _________

    That's all for now. if you have anyQuestion, well you can mail me at mrbrl@hotmail.com

      • avatar
      • Niel
      • Wed 15 Jan 2003

      Content-Base

      I noticed when using the sendMessage with the URL option the named anchors within the document would not work. If I sent an HTML message to a user with MS Outlook and they clicked on a link to an anchor within the same page (a href="#MYANCHOR") (a name="MYANCHOR") it would launch their browser and take them to the Content-Base that is set in the in the method. Should I have created the anchors or links differently?

      Overall this has been a great solution. Thanks!

      • avatar
      • M Black
      • Mon 16 Feb 2004

      Re: SEND HTML WITH LOTUS WITHOUT TOUCHING THE SERVER

      Hi.

      I'm new to Domino and LotusScript.

      Can anyone tell me why this works? I don't see why when the HTML is put on the clipboard and then pasted into an email body that it doesn't just display all the tags when the email gets sent.

      Thanks! M

  17. How About file attachments?

    This is great. It has worked so well that now I am getting requests for adding attachments. Is there a way for any files uploaded to become attachments?

    • avatar
    • Fred Delay
    • Mon 12 May 2003

    send mass mail

    Hi, I wanted to send mass mail to thousands of recipients. Then I noticed that only about 700 in one flow, I presume it' s a problem of field size of rcpt. Then I decided to write a loop around the send function to send only an allowed number of mails in one flow, but the second time I call the function, it crashes with null pointer exception.

    any ideas on that?

      • avatar
      • Mark Spanne
      • Thu 23 Oct 2003

      Re: send mass mail

      hi, did you find a solution? I have the same problem, I thought it would help to instantiate the htmlmessage for each run newly but then it crashed again.

      HtmlMessage msg = new HtmlMessage( sSMTPHostAddress );

  18. Agent ran but won't terminate

    In the server console, it says executing agent... and there is no way to terminate it, event quit the server, the server won't quit.

    Any idea?

    Also, when encountered error, and agent tried to resend the document, it says SMTP don like our RCPT ..

    Any idea?

    ------------------- GREAT WORK!!... I have been figuring out how to send smtp and url via Domino before this, also tried the getdocumentbyurl and never success.

  19. Adding notes fields in the mail message

    Hello Jake,

    Thanks a lot for this set of very interesting articles.

    I'd like to add the following info if you don't already know :

    If we take your example with Socket Workbench :

    HELO YourComputerName (optional) MAIL FROM: <Sender's E-mail Address> RCPT TO: <Recipient's E-mail Address> DATA From: Sender's Alias <Sender's reply e-mail address> To: Receiver's Alias <Recipient's e-mail address> Subject: <Subject Goes Here> REUTERSCODE: IBM.N RISK: R1 COUNTRY: USA

    <body goes here> . QUIT

    Please note that I added some extra info like REUTERSCODE, RISK and COUNTRY (No space allowed) in the header.

    Now if you send the mail and check it with the Notes Client you will see that you now have fields in the memo document with the same name and values.

    Imagine in an intranet context what you can do with a mailing database that receive those kind of mail. They can be easily processed by an agent that access directly those fields.

    If you use the JavaMail API you can use the following method of the javax.mail.internet.MimeMessage class : addHeader(java.lang.String name, java.lang.String value) where name is the name of the field and value the value.

    Thanks again for all the usefull information you provide us all.

    Best regards, Nicolas TISSIER

    P.S. feel free to modify the subject if it is not explicit enough.

      • avatar
      • Jake Howlett
      • Wed 11 Jun 2003

      Re: Adding notes fields in the mail message

      Merci Nicolas,

      Interesting idea. I shall add it to my list of things to investigate.

      Jake

  20. Don't display HTML mail

    Hi all,

    My problem is my recived mail html. The document contains .css and imagin what no displayed in notes.

  21. Platform independent??

    Hi Jake,

    Great article. I was using your other LotusSctipt solution wing the winsock dll and LotusScript, but my client is moving to a Linux server environment. Is this Java method platform independent??

    Cheers, Niall.

    • avatar
    • PKS
    • Fri 12 Aug 2005

    Converting Domino mails using APIs

    Hi, I have a document management system, built on MS technologies. It basically archives documents from a particular folder. Now the user also wants to add the feature so that SMTP mails can also be archived using the existing system. For Outlook, we have written programs to convert mails selected by users in to .oft format and save in the folder. Rest is taken care from there, by the existing system. It (.oft)also keeps the header and attachment info of the mail. We need to implement something similar for Notes mails. How should I do this - Converting selected mail in to .oft format, along with it's header info and attachment info/link. Do I need to write APIs to achive this. Should these be C, C++ or JAva APIs. I have not worked on APIs before. Kindly suggest.

    Thanks!

  22. Change who an email is from

    Hey Jake, is there a way to simply change who the email is from without having to use all of this.

    Its great and I can make something like this work, but it would be nice to just have a field call From (or something) in the form and call it when sending the email.

    If you don't know then please don't waste any time on it.

    Thanks dude,

    Aaron

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:



Navigate other articles in the category "Java"

« Previous Article Next Article »
Sending HTML mail via SMTP part 2   None Found

About This Article

Author: Jake Howlett
Category: Java
Keywords: SMTP; Mail; Socket; HTML;

Attachments

htmlmail-1.2.zip (78 Kbytes)

Options

Feedback
Print Friendly

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »