sending Email with Attachment xpages -
this sample coding sending email attachment. content of word not send correctly.
attachment using "file upload"
// write mail var setdoc:notesdocument = database.getprofiledocument("system setting", ""); var server = setdoc.getitemvaluestring("maildbsvr"); var dname = setdoc.getitemvaluestring("maildbpath"); var web = setdoc.getitemvaluestring("internetaddress"); var maildoc:notesdocument = database.createdocument(); maildoc.replaceitemvalue("form", "memo"); maildoc.replaceitemvalue("subject","test send mail"); session.setconvertmime(false); var stream = session.createstream(); stream.writetext("<html><body>"); stream.writetext("<p>dear " + "[person]" + ",</p>"); stream.writetext("<p>attached item image of </p>"); stream.writetext("<p> ***this automated message - please not reply directly email***</p>"); stream.writetext("</body></html>"); var body = maildoc.createmimeentity("body"); var att= document1.getdocument(true).getfirstitem("attachment"); maildoc.copyitem(att,"body") // try adding item body.setcontentfromtext(stream, "text/html;charset=utf-8", 1725); stream.close(); maildoc.closemimeentities(true); session.setconvertmime(true); maildoc.replaceitemvalue("sendto","testuser1@devsvr1.pcs.com.my"); maildoc.send();
the result come out attachment field without text value inside. not sure part of wrong.
sample result screen:
recommended mime style
var htmlmail = function() { ... } var mail = new htmlmail(); mail.setto("testuser1@devsvr1.pcs.com.my") //mail.addfileattachment(result); mail.setsubject("test send mail"); mail.addhtml("<h1>hi!</h1>"); mail.addhtml("<table><tbody><tr><td>contents in table here</td></tr></tbody></table>"); mail.send();
ibm notes/domino has 2 ways show 'pretty words , pictures'
- richtext
- mime
you should use 1 or other, here mixing both different types.
above, when copy attachment item, adding first 'body' item, can see it's type 'richtext'. createmimeentity creating second 'body' item, , it's type 'mimepart' (it showing second because mime not applied until closemimeentities) have 2 body items different parts. seeing 'richtext' attachment in notes because first listed item.
what need create correct multipart mime structure. if want bit more information mime, blog post on site explains little bit more, including info correct mime structure. http://camerongregor.com/2016/04/21/webmail-ui-you-must-learn-about-mime/
if haven't seen yet there xsnippet mark leusink has demo of creating mime email using ssjs. don't use myself don't use ssjs might useful should handle of mime manipulation you. https://openntf.org/xsnippets.nsf/snippet.xsp?id=create-html-mails-in-ssjs-using-mime
Comments
Post a Comment