May 25, 2011

Sending an email with embedded images using WhizBase

WhizBase has a built-in functions for sending a rich-text (HTML) emails. In your email you can easily include an absolute URL to any image and/or multimedia contents located on your server, but if you do that, in most cases the recipient will not see them automatically (security measure). To avoid this you should embed the images and other multimedia files in the body of your email. Embedding files using WhizBase is a simple task.
To illustrate this we will create a simple email template:
File email.wbsp
<!--
[FormFields]
WB_command=P
WB_mailserver=mail.whizbase.com
WB_from=admin@whizbase.com
WB_to=$wbv{email}
WB_mailauth=L
WB_mailuser=someuser
WB_mailpass=somepass
-->
<!--WB_BeginTemplate-->
<html>
<body>
<img src="http://www.whizbase.com/images/logo.jpg"><br>
Thank you for subscribing with us!<br>
</body>
</html>


This WBSP code will send an email that will not show the logo image to the recipient automatically. Now we will do few modifications to embed the logo.jpg to our email:
File emailembed.wbsp
<!--
[FormFields]
WB_command=P
WB_mailserver=mail.whizbase.com
WB_from=admin@whizbase.com
WB_to=$wbv{email}
WB_mailauth=L
WB_mailuser=someuser
WB_mailpass=somepass
WB_embed=/images/logo.jpg
-->
<!--WB_BeginTemplate-->
<html>
<body>
<img src="$wbcid[/images/logo.jpg]"><br>
Thank you for subscribing with us!<br>
</body>
</html>

As you can see we just added a WB_embed variable to include the file /images/logo.jpg in the body of the email message (MIME encoded) and changed the reference to file logo.jpg to use embedded image using WB function $WBCID.