Skip to main content
Currently, the mail event in K2 Studio sends out plaintext email messages. But I need to send out HTML messages, along with embeded images in the email.

What I mean by embeded is that the images are encoded in the email itself, and is not stored externally and referred to by <img src="..."> tag.

How do achieve this? Any advise appreciated.
there is a knowledge article on how to send emails as HTML:

http://kb.k2workflow.com/Articles/KB000003.aspx

basically, you would create HTML in the message body using code, like this:




Sub Main(ByVal K2 As ServerEventContext)
SMTPFunction(K2)
End sub
Function SMTPFunction(Byval K2 as ServerEventContext)
Dim objMsg As New System.Web.Mail.MailMessage()
Dim objAttachment As System.Web.Mail.MailAttachment
Dim objSender As System.Web.Mail.SmtpMail
Dim strFrom as String
Dim strEmail As String
Dim strSubject As String
Dim strBody As String
Dim oXMLDoc As New System.Xml.XMLDocument()
Dim oNode As System.Xml.XMLNode
objSender.SmtpServer = "scsapdc"
strFrom = "workflow"
strEmail = K2.ProcessInstance.Originator.Email
strSubject = "Test HTML Mail"
strBody = "<HTML>" & _
"<BODY bgcolor=""#ffff66"">" & _
"<DIV align=""left""><font face=""verdana"" size=""1""><b>This is my test HTML Email</b></font></DIV>" & _
"<DIV align=""left""><font face=""verdana"" size=""2"" color=""#cc0033""><b>This is my test HTML Email</b></font></DIV>" & _
"<DIV align=""left""><font face=""verdana"" size=""3"" color=""#0000cc""><b>This is my test HTML Email</b></font></DIV>" & _
"</BODY>" & _
"</HTML>"
objMsg.From = strFrom
objMsg.To = strEmail
objMsg.Subject = strSubject
objMsg.Body = strBody
objMsg.BodyFormat = Web.Mail.MailFormat.Html
objSender.Send(objMsg)
End Function


I am not sure how to embed an image into this HTML, though.
I have read this article, but it is not what I have in mind as this involves externally-linking the images.

Here is what I have a mind:

1. Use an external mail client to compose a HTML email (with embeded images) and placeholders in which the content is to be inserted later.

2. Save the generated HTML code into an external file, or insert it onto a database table.

3. In the K2 mail event, write a custom method to retrieve the generate HTML code and replace the placeholders with my personalized mail content.

I don't know if there are other better methods. Comments?

Reply