Cyclone3 Skin

Create and send email

From Cyclone3 Wiki

Cyclone3 has support for sending mails directly using the application 130. Error handling and storing sent email is handled automatically. The following example illustrates creating and sending mails.

Create mail

use Mime::Entity;
use TOM::Net::email;
use TOM::Utils::datetime;

note: my@domain.tld is explicitely typed 2x

my $to = 'email@domain.tld;my@domain.tld;another@domain.tld;my@domain.tld';
my $date = TOM::Utils::datetime::mail_current();
my $body = "<html><body>example text</body></html>";

Create message object

my $msg = MIME::Entity->build
(
   'Type'    => "multipart/mixed", # don't use multipart/related
   'List-Id' => "Cyclone3",
   'Date'    => $date,
   'From'    => "Example.tld e-shop <eshop\@example.tld>",
   'To'      => TOM::Net::email::convert_TO($to),
   'Subject' => "Order No. #0001"
);

attach html email body

$msg->attach
(
   'Data' => $body,
   'Type' => "text/html;charset=\"UTF-8\"",
   'Encoding' => "base64", # or 8bit
);

attach cyclone3 icon inline :)

$msg->attach
(
   'Path'       => $TOM::P."/_data/logo.gif",
   'Type'       => "image/gif",
   'Content-ID' => "<logo\@cyclone3.org>",
   'Encoding'   => "base64"
);

attach PDF file as attachment

$msg->attach
(
   'Path'       => $TOM::P."/_data/document.pdf",
   'Type'       => "application/pdf",
   'Encoding'   => "base64",
   'Disposition'=> "attachment",
);

Send email

TOM::Net::email::send(
   'to'=> $to,
   'body'=> $msg->as_string(),
);

See Also