Reputation: 16438
I am trying to send email with attachment in tcl with the help of 'sendmail'
and I am using the following code
set msg {From: dinesh}
append msg \n "To: " [join $recipient_list ,]
append msg \n "Cc: " [join $cc_list ,]
append msg \n "Subject: $subject"
append msg \n\n $body
exec /usr/lib/sendmail -oi -t << $msg
Now, I want to highlight the body content so that when the user receives it can see it with bold or italic or background or foreground of any format.
I tried with HTML tags, but unable to get it in HTML format, instead I got the literal texts.
Is it possible use HTML kind of color coding with sendmail
?
Upvotes: 0
Views: 883
Reputation: 137707
To send email that will be interpreted by the other end as having styling, you've got to send the message body in a format that supports embedded styling (such as HTML) and you've got to send the MIME headers that say that the body is that format (i.e., HTML content is associated with the content type text/html
).
Assembling a MIME message is rather annoying, but there's a package in Tcllib to help:
package require mime
# Construct the body
set html "<h1>A test</h1>This is <i>a test</i> of MIME message composition."
set token [mime::initialize -canonical text/html -string $html]
# Add in the headers for email
mime::setheader $token From dinesh
mime::setheader $token To [join $recipient_list ,]
mime::setheader $token Cc [join $cc_list ,]
mime::setheader $token Subject $subject
# Serialize to a string
set message [mime::buildmessage $token]
mime::finalize $token
### How to check for sanity: puts $message
# Send the message
exec /usr/lib/sendmail -oi -t << $message
You could use the smtp
package from Tcllib to do the sending too (and it integrates well with the mime
package) but if exec /usr/lib/sendmail
works, stick with it.
Be aware that showing the resulting message as styled requires the coöperation of the receiving client. Also be aware that it's conventional to send the content unstyled as well, as plain text in a multi-part message. Assembling such complex things is when using the mime
package helps a lot.
Upvotes: 1