When the $attachments.addAttachment() function is called it creates an attachment output stream in which the file data is sent. It also generates a unique identifier, a cid, associated with the file data in the output stream. The cid, which is an ordinary string, is returned to the caller. The cid can be used in, for example,
<img> and
<a> tags to reference the file data.
#set($img=$attachments.addAttachment('C:\images\img1.jpg',
'im.jpg', 'image/pjpeg'))
In the Template Engine template <img src="$img"/> is used to reference the file data. The Template Engine output will have the cid as reference, for example:
<img src="cid:57E498EB-8E08-9E46-9FCC-B59CB41280CB">
$attachments.addAttachment(<uri>, <name>, <contentType>)
uri
|
Use http:// if the file is available on a web server or content management system.
Use resource:// if the file is stored as a resource in the runtime repository. See Resource output connector in the Connectors documentation or Resource filter in the Design Center documentation for information about how to store the resources.
Use otmm:// if the file is an OpenText Media Management (OTMM) asset. You must first create a Media Management connection profile (see the Profile configurations documentation). When you have the connection profile you can reference an asset using the following URI:
otmm://<profileName>/<reference>
Where <reference> is either the path to the resource or ?id=<GUID>, for example ?id=9E664C0E-807F-024C-8885-659C6EC6E9C8.
|
name
|
|
contentType
|
|
In the Template Engine template you can call the $attachments.addAttachment() function and reference the corresponding attachment in different ways. Some valid example are illustrated below.
<img src="$attachments.addAttachment('C:\abc\img.jpg', 'im.jpg', 'image/pjpeg'))"/>
#set($att="$attachments.addAttachment('C:\abc\img.jpg', 'im.jpg', 'image/pjpeg'))")
<img src="$att"/>
#set($path='C:\abc\img.jpg')
#set($name='im.jpg')
#set($ct='image/pjpeg')
<img src="$attachments.addAttachment($path, $name, $ct)"/>
If you only declare a variable for the attachment, e.g. #set($img=$attachments.addAttachment('C:\images\img1.jpg', 'im.jpg', 'image/pjpeg')), the file is added as an attachment to the email. The email recipient must click the attachment to view the content in this case.
If you add an <a> tag to the Template Engine template, the email recipient can click a link to view the content of an attachment. For example:
#set($r=$attachments.addAttachment('C:\abc\img.jpg', 'im.jpg', 'image/pjpeg'))
<a href="$r">Link text</a>
If the attachment is an image you can add an <img> tag to the Template Engine template and have the image displayed in the email body. For example:
#set($r=$attachments.addAttachment('C:\abc\img1.jpg', 'Dog', 'image/pjpeg'))
<img src="$img1"/>
If you try to reference different files using the same attachment name, the cid is associated with the file you reference first. This means the same file will be used for both references in the output.
#set($abc=$attachments.addAttachment('C:\images\Dog.jpg', 'Animal.jpg', 'image/pjpeg'))
<img src="$abc"/>
#set($xyz=$attachments.addAttachment('C:\images\Cat.jpg', 'Animal.jpg', 'image/pjpeg'))
<img src="$xyz"/>
<img src="cid:70179CF0-C9A0-5D4D-B4D2-32CFBC5E0639">
<img src="cid:70179CF0-C9A0-5D4D-B4D2-32CFBC5E0639">
The $attachments.addAttachment function is used to attach external resources to an email. To attach resources in a document definition to an email you must use the
toAttachment() function. See
toAttachment().
#set($img=$attachments.addAttachment('C:\abc\Dog.jpg', 'Dog.jpg', 'image/pjpeg'))
<p>See attachment Dog.jpg.</p>
<p>See attachment Dog.jpg.</p>
The file Dog.jpg is attached as
Dog.jpg to the email. The recipient must click the attachment to view the content.
#set($info=$attachments.addAttachment('C:\abc\Info.txt', 'Info.txt', 'text/plain'))
<p><a href="$info">See this information</a></p>
<p><a href="cid:06474328-D808-B642-B748-E8D294283E49">See this information</a></p>
The file Info.txt is attached as
Info.txt to the email. The recipient must click the "See this information" link to view the content.
#set($img=$attachments.addAttachment('C:\abc\Dog.jpg', 'Dog.jpg', 'image/pjpeg'))
<img src="$img"/>
<img src="cid:6E8D6107-90E2-6E41-99BF-308E7E93C2FA">
The file Dog.jpg is attached as
Dog.jpg to the email and displayed in the email body.
#set($img=$attachments.addAttachment('..\data\images\Dog.jpg', 'Dog.jpg', 'image/pjpeg'))
<img src="$img"/>
<img src="cid:6E8D6107-90E2-6E41-99BF-308E7E93C2FA">
#set($css1=$attachments.addAttachment("C:\abc\myCss.css", "TheCss.css", "text/css"))
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="$css1"></head>
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="cid:8F19F2DE-F115-DA4B-9B40-30C9078D7E6A"></head>
The file myCss.css is attached as
TheCss.css to the email and referenced in the
<link> tag. This CSS is used as stylesheet for the email.