Cyclone3 Skin

Create and send email

From Cyclone3 Wiki

(Difference between revisions)
(See Also)
Current revision (13:36, 25 October 2011) (edit) (undo)
(Create mail)
 
Line 17: Line 17:
my $msg = MIME::Entity->build
my $msg = MIME::Entity->build
(
(
-
'Type' => "multipart/related",
+
'Type' => "multipart/mixed", # don't use multipart/related
'List-Id' => "Cyclone3",
'List-Id' => "Cyclone3",
'Date' => $date,
'Date' => $date,
Line 31: Line 31:
'Data' => $body,
'Data' => $body,
'Type' => "text/html;charset=\"UTF-8\"",
'Type' => "text/html;charset=\"UTF-8\"",
-
'Encoding' => "8bit",
+
'Encoding' => "base64", # or 8bit
);
);
-
attach cyclone3 icon :)
+
attach cyclone3 icon inline :)
$msg->attach
$msg->attach
Line 42: Line 42:
'Content-ID' => "<logo\@cyclone3.org>",
'Content-ID' => "<logo\@cyclone3.org>",
'Encoding' => "base64"
'Encoding' => "base64"
 +
);
 +
 +
attach PDF file as attachment
 +
 +
$msg->attach
 +
(
 +
'Path' => $TOM::P."/_data/document.pdf",
 +
'Type' => "application/pdf",
 +
'Encoding' => "base64",
 +
'Disposition'=> "attachment",
);
);

Current revision

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