Skip to content

Attachments

The file attachments problem

Attachments are a historical enemy of email marketing for, among others, the following reasons:

  • The files may contain viruses or other security threats.
  • Attachments are embedded in the email making it take up much more space.
  • The campaigns become slower.

Mail providers are forced to scan files for viruses and need to consume more transfers and bandwidth to manage them.

That is why email marketing tools do not usually support or strongly discourage the use of attachments.

The recommendation for cases in which you need to send a file by email is to link said file instead of attaching it, this offers a series of improvements:

  • The files are not embedded in the email, so it is lighter.
  • By using links it is possible to track their opening
  • The file can be altered once the campaign has been sent.

Sending attachments

Despite being discouraged, teenvio allows the sending of attached files for some of its plans. For this, the following parameters can be used in the sending requests:

  • attachmen_base64raw: String with the content of the file in base64
  • attachmen_filename: File name

See the POST /campaign/ and POST /bulkcampaign/ methods for more info.

Embedded images

There is the possibility to include an attached image and have it used in the HTML instead of using an external resource in your href. This functionality corresponds to the _rfc2392 standar. Thanks to this it is possible to view an image without the manager asking if we want to show external resources.

To use this functionality, you must add an attached file with a PNG or JPG image whose combo matches the name of the piece or template. The file name in the template must not contain paths and must be just the file name.

To consider

If our creative only has one image and we use this method to embed it, we can have collateral damage: The recipients may not authorize the display of external resources (since the main image is already displayed) and thus prevent the platform from knowing the openings actual shipment.

Example using the transactional method:

export TE_TOKEN='Your token'

curl -X POST https://app.teenvio.com/v4/public/api/rest/v3/bulkcampaign/ \
-H "X-Token: $TE_TOKEN" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '
{
    "rid" : 1,
    "name" : "transactional image test from api",
    "subject" : "subject transactional image email",
    "recipients" : [
        "contact1@domain.com",
        "contact2@domain.com"
    ],
    "vars" : {
        "descuento" : 20,
        "caducidad" : "noviembre"
    },
    "html_body" : "<html><img src=\"header.png\"><p>Hola mundo con imagen incrustada</p> <p>Por cierto, tu descuento del [[[descuento]]]% caduca en [[[caducidad]]]</p></body>",
    "attachmen_base64raw" : "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAHElEQVQ4y2M0+M9ANmBiYBjVPKp5VPOo5oHUDAAGPAFXwSLvZAAAAABJRU5ErkJggg==",
    "attachmen_filename" : "header.png"
}'
<?php

$token = 'Your token';

$url_base = 'https://app.teenvio.com/v4/public/api/rest/v3'

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_URL => $url_base.'/bulkcampaign/',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => array(
        'Accept: application/json',
        'X-Token: '.$token,
        'Content-Type: application/json'
    ),
    CURLOPT_POSTFIELDS => '
        {
            "rid" : 1,
            "name" : "transactional image test from api",
            "subject" : "subject transactional image email",
            "recipients" : [
                "contact1@domain.com",
                "contact2@domain.com"
            ],
            "vars" : {
                "descuento" : 20,
                "caducidad" : "noviembre"
            },
            "html_body" : "<html><img src=\"header.png\"><p>Hola mundo con imagen incrustada</p> <p>Por cierto, tu descuento del [[[descuento]]]% caduca en [[[caducidad]]]</p></body>",
            "attachmen_base64raw" : "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAHElEQVQ4y2M0+M9ANmBiYBjVPKp5VPOo5oHUDAAGPAFXwSLvZAAAAABJRU5ErkJggg==",
            "attachmen_filename" : "header.png"
        }
    '
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
import requests

token = 'Your token'

url_base = 'https://app.teenvio.com/v4/public/api/rest/v3'

my_headers = {
    'Accept' : 'application/json',
    'X-Token' : token,
    'Content-Type' : 'application/json'
}
post_request = {
    "rid" : 1,
    "name" : "transactional image test from api",
    "subject" : "subject transactional image email",
    "recipients" : [
        "contact1@domain.com",
        "contact2@domain.com"
    ],
    "vars" : {
        "descuento" : 20,
        "caducidad" : "noviembre"
    },
    "html_body" : "<html><img src=\"header.png\"><p>Hola mundo con imagen incrustada</p> <p>Por cierto, tu descuento del [[[descuento]]]% caduca en [[[caducidad]]]</p></body>",
    "attachmen_base64raw" : "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAHElEQVQ4y2M0+M9ANmBiYBjVPKp5VPOo5oHUDAAGPAFXwSLvZAAAAABJRU5ErkJggg==",
    "attachmen_filename" : "header.png"
}

response = requests.post(url_base+"/bulkcampaign/", json=post_request, headers=my_headers)

print(response.json())
const axios= require('axios');

const token = 'Your token';

const url_base = 'https://app.teenvio.com/v4/public/api/rest/v3';

const my_headers = {
    'Accept' : 'application/json',
    'X-Token' : token
};

const post_request = {
    "rid" : 1,
    "name" : "transactional image test from api",
    "subject" : "subject transactional image email",
    "recipients" : [
        "contact1@domain.com",
        "contact2@domain.com"
    ],
    "vars" : {
        "descuento" : 20,
        "caducidad" : "noviembre"
    },
    "html_body" : "<html><img src=\"header.png\"><p>Hola mundo con imagen incrustada</p> <p>Por cierto, tu descuento del [[[descuento]]]% caduca en [[[caducidad]]]</p></body>",
    "attachmen_base64raw" : "iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAHElEQVQ4y2M0+M9ANmBiYBjVPKp5VPOo5oHUDAAGPAFXwSLvZAAAAABJRU5ErkJggg==",
    "attachmen_filename" : "header.png"
}

axios.post(url_base+'/bulkcampaign/', post_request, {headers:my_headers}).then(resp => {
    console.log(resp.data);
});

Response:

{
    "action": "send_bulk_campaign",
    "time": "2022-10-26 14:39:29",
    "status": "OK",
    "response": 1334,
    "code": 0
}