I am trying to add image in Gmail.
I had inserted image url in my email template and had set it.
The sent gmail has included images, but is not displayed.
of course email sending is success and the other params is displayed.
Images is encode in base64.
Doesn’t gmail support images in base64?
If it is true, how to fix it?
================= Email Send Action =============================
$transport = $transportBuilder
->setTemplateIdentifier($template[‘template_id’])
->setTemplateOptions(
[
‘area’ => MagentoFrameworkAppArea::AREA_FRONTEND,
‘store’ => $this->getStoreId()
]
)
->setTemplateVars($templateParams)
->addAttachment(
$body,
‘image/jpeg’,
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_BASE64,
$imageName
)
->setFrom($sender)
->addTo( $receiver[’email’], $receiver[‘name’] )
->getTransport();
$transport->getMessage()->setMessageType( MagentoFrameworkMailMessageInterface::TYPE_HTML);
$transport->sendMessage();
====================== addAttachement function ================================
\ModelMailTemplate;
use MagentoFrameworkMailTemplateTransportBuilder as MagentoTransportBuilder;
use Zend_Mime;
use Zend_Mime_Part;
class TransportBuilder extends MagentoTransportBuilder
{
private $parts = [];
public function addAttachment(
$body,
$filename = null,
string $mimeType = Zend_Mime::TYPE_OCTETSTREAM,
string $disposition = Zend_Mime::DISPOSITION_ATTACHMENT,
string $encoding = Zend_Mime::ENCODING_BASE64
) {
$mp = new Zend_Mime_Part($body);
$mp->encoding = $encoding;
$mp->type = $mimeType;
$mp->disposition = $disposition;
$mp->filename = $filename;
$this->parts[] = $mp;
return $this;
}
}