<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
<channel>
<title>CodeStore.net comments on "Java Class For Sending HTML Emails from Lotus Domino"</title>
<description>Replies to blog "Java Class For Sending HTML Emails from Lotus Domino" on codestore.net.</description>
<link>http://www.codestore.net/</link>
<lastBuildDate>Sun, 14 Aug 2011 04:35:47 -0500</lastBuildDate>
<atom:link href="http://www.codestore.net/store.nsf/blog.xml?Open=20100108-0129" rel="self" type="application/rss+xml" />

<item>
	<title>Reply from Jie Cerbo</title>
	<pubDate>Sun, 14 Aug 2011 04:35:47 -0500</pubDate>
	<author>Jie Cerbo</author>
	<description><![CDATA[ 
		<p>I know this is an old thread but I hope somebody can still help me.</p>
		<p>I have done something similar in C#. However I'm encountering an issue when i am attaching multiple files with different file types. For example, I am attaching an excel file and a word file. When the mail is received in lotus notes client only the first attachment can be opened, the second attachment gives an error that the file is in a different format. Following is the code i'm using:</p>
		<p>********</p>
		<p>public static void sendLotusFormat()</p>
		<p>{</p>
		<p>Domino.NotesSession session = new Domino.NotesSession();</p>
		<p>string password = "&lt;lotusmailpassword&gt;";</p>
		<p>session.Initialize(password);</p>
		<p>object itemvalue = null;</p>
		<p>String mailServer = ConfigurationManager.AppSettings["lotusmailserver"];</p>
		<p>String mailFile = "&lt;path to names.nsf&gt;";</p>
		<p>Domino.NotesDatabase email = session.GetDatabase(mailServer, mailFile, false);</p>
		<p>if (!email.IsOpen) email.Open();</p>
		<p>Domino.NotesDocument memo = email.CreateDocument();</p>
		<p>memo.ReplaceItemValue("Form", "Memo");</p>
		<p>memo.ReplaceItemValue("Subject","Subject");</p>
		<p>string mess = someHTMLformattedmessage;</p>
		<p>memo.ReplaceItemValue("SendTo", mailaddress);</p>
		<p>memo.SaveMessageOnSend = true;</p>
		<p>itemvalue = memo.GetItemValue("SendTo");</p>
		<p>session.ConvertMime = false;</p>
		<p>Domino.NotesStream stream = session.CreateStream();</p>
		<p>stream.WriteText(mess, Domino.EOL_TYPE.EOL_ANY);</p>
		<p>Domino.NotesMIMEEntity mimeBody = memo.CreateMIMEEntity("Body");</p>
		<p>Domino.NotesMIMEEntity mimeHtml = mimeBody.CreateChildEntity(null);</p>
		<p>Domino.NotesMIMEHeader header = mimeBody.CreateHeader("Subject");</p>
		<p>//For the HTML part of the message</p>
		<p>mimeHtml.SetContentFromText(stream, "text/html; charset=\"iso-8859-1\"", Domino.MIME_ENCODING.ENC_QUOTED_PRINTABLE);</p>
		<p>stream.Close();</p>
		<p>stream.Truncate();</p>
		<p>//This is for looping through an arraylist with names of the files to be attached</p>
		<p>if (file.Count &gt; 0)</p>
		<p>{</p>
		<p>String fileName = "";</p>
		<p>foreach (string i in file)</p>
		<p>{</p>
		<p>fileName =i.Substring(i.LastIndexOf("\\") + 1);</p>
		<p>mimeHtml = mimeBody.CreateChildEntity(null);</p>
		<p>header = mimeHtml.CreateHeader("Content-Disposition");</p>
		<p>header.SetHeaderVal("attachment; filename=" + fileName);</p>
		<p>header = mimeHtml.CreateHeader("Content-ID");</p>
		<p>header.SetHeaderVal(fileName);</p>
		<p>stream = session.CreateStream();</p>
		<p>if (stream.Open(i, "binary"))</p>
		<p>{</p>
		<p>mimeHtml.SetContentFromBytes(stream, "application/octet-stream", Domino.MIME_ENCODING.ENC_IDENTITY_BINARY);</p>
		<p>mimeHtml.EncodeContent(MIME_ENCODING.ENC_BASE64);</p>
		<p>}</p>
		<p>stream.Close();</p>
		<p>stream.Truncate();</p>
		<p>}</p>
		<p>}</p>
		<p>memo.Send(false, ref itemvalue);</p>
		<p>memo.Save(true, false, false);</p>
		<p>stream.Close();</p>
		<p>session.ConvertMime = true;</p>
		<p>memo.CloseMIMEEntities(true, "Body");</p>
		<p>memo.ComputeWithForm(true, false);</p>
		<p>}</p>
		<p>********</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=9D4D008AD2B4A023862578EC0034B6BE"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20100108-0129?OpenDocument#DOC_9D4D008A</link>
</item><item>
	<title>Reply from Jyri</title>
	<pubDate>Tue, 31 Aug 2010 06:41:26 -0500</pubDate>
	<author>Jyri</author>
	<description><![CDATA[ 
		<p>Hi Jake,</p>
		<p>It would be nice to see how you solved adding attachment to HTML email (using Java). </p>
		<p>Jyri</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=AC60073A61D2F5B086257790004037AA"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20100108-0129?OpenDocument#DOC_AC60073A</link>
</item><item>
	<title>Reply from Jake Howlett</title>
	<pubDate>Fri, 08 Jan 2010 08:09:03 -0600</pubDate>
	<author>Jake Howlett</author>
	<description><![CDATA[ 
		<p>Hi Steve. Funnily enough that's pretty much exactly what I did after blogging the above. I now have a method of my Email class to add a file.</p>
		<p>One thing I did find is that I needed to have a root MIME entity that was "multipart/mixed", which contained the file as well as a child MIME entity of type "multipart/alternative", which contained the text and HTML of the message.</p>
		<p>Without the parent "mixed" entity it would work in Notes client but not Thunderbird (and I guess others)</p>
		<p>Jake</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=27443CFB57CAFA6C862576A5004DBBAF"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20100108-0129?OpenDocument#DOC_27443CFB</link>
</item><item>
	<title>Reply from Steve M</title>
	<pubDate>Fri, 08 Jan 2010 07:57:37 -0600</pubDate>
	<author>Steve M</author>
	<description><![CDATA[ 
		<p>Hi Jake</p>
		<p>I have done something similar to addFileAttachment() in my own email class. </p>
		<p>I was actually creating the attachment to order at run time rather attaching an existing one, so it may not fit your needs but in case it is of use or can be modified I'll explain the idea behind it :</p>
		<p>In the class, the various MIME headers only get put together at the time the 'send' method is called. By this point I've already got my HTML text stored as a stream and the text I want to go in the attachment in another stream. Both streams are properties of the email object. I have an additional string property of the object that has the desired name of the file attachment (textAttachFileName).</p>
		<p>The 'send' method sets the MIME headers for the text & HTML parts in the usual way but then creates a new header and child entity that specifically represent the attachment. In the below code the "textAttachStream" can be any text stream you want and is used as the content of the attachment - you may be able to change this bit to write a byte stream instead if your attachment already exists.</p>
		<p>Hope that makes sense - happy to send more details if needed.</p>
		<p>Thanks for a fantastic blog by the way.</p>
		<p>Steve</p>
		<p>'########################</p>
		<p>'A new child mime entity to hold a file attachment </p>
		<p>Dim header As NotesMIMEHeader		</p>
		<p>Dim bodyChild As NotesMIMEEntity</p>
		<p>Set bodyChild = body.CreateChildEntity()</p>
		<p>Set header = bodyChild.createHeader("Content-Type")</p>
		<p>Call header.setHeaderVal("multipart/mixed")</p>
		<p>Set header = bodyChild.createHeader("Content-Disposition")</p>
		<p>Call header.setHeaderVal("attachment; filename=" & textAttachFileName ) </p>
		<p>Set header = bodyChild.createHeader("Content-ID")</p>
		<p>Call header.setHeaderVal( textAttachFileName ) </p>
		<p>Call bodyChild.SetContentFromText( textAttachStream, textAttachMimeType, ENC_IDENTITY_7BIT)</p>
		<p>'########################</p>

		<p><a href="http://www.codestore.net/store.nsf/reply?OpenForm&ParentUNID=91A134A938AACDAE862576A5004CAF70"><img border="0" src="http://www.codestore.net/store.nsf/images/rss_reply.gif" alt="Click here to post a response" /></a></p>
	]]></description>
	<link>http://www.codestore.net/store.nsf/unid/BLOG-20100108-0129?OpenDocument#DOC_91A134A9</link>
</item>

</channel>
</rss> 
