Perl MIME::Lite piece jointe txt n'apparait pas avec body HTML + images imbriquées
Le
jpc
Bonjour,
Je cherche à envoyer un email HTML avec images imbriquées avec
MIME::Lite et avec une pièce jointe au format .txt
Tout marche mais la piéce jointe au format n'apparait pas à cause de
Type =>'multipart/related'
qq a-t-il une solution ?
code :
#############################################
#!/usr/bin/perl
use MIME::Lite;
use strict;
$msg = MIME::Lite->new(
From =>'xxxx@orange.fr',
To =>'xxxxx@orange.fr',
Subject =>'Envoi de l\'email via Perl!',
Type =>'multipart/related',
);
$msg->attr("content-type.charset" => "iso-8859-1");
$msg->attach(Type => 'text/html',
Data => qq{
<body>
<BR>
<img src="cid:header.jpg">
<BR>
<div style="width: 660px; font-family: Verdana; font-size:
11px; padding: 20px 10px 20px 10px;">
<div style="margin-left: 30px; margin-right: 60px;">
<div style='font-family: Verdana; font-size: 12px; font-weight:
bold; color: #628ED3; padding: 10px 0px 15px 0px; margin: 10px 0px
5px
0px; border-bottom: 1px solid #628ED3;'>BackUp test test
XXX</div><div style='font-family: Verdana; font-size: 10px; padding:
0px
0px 15px 0px; margin: 0px 0px 5px 0px; border-bottom: 1px solid
#628ED3;'>BackUp ok voir le document joint.</div>
<BR>
<img src="cid:footer.jpg">
<BR>
</body>
}
);
$msg->attach
(
Type => 'image/jpg',
Id =>'footer.jpg',
Path => 'footer.jpg'
);
$msg->attach(
Type => 'image/jpg',
Id => 'header.jpg',
Path => 'header.jpg'
);
# piece jointe au format txt
$msg->attach(Type => 'application/txt',
Path => 'BackUp_Database.log',
Filename => 'BackUp_Database.log',
);
$msg->send('smtp', 'xxx.xxx.xx.xx');
#########################################
Merci,
JPC
Je cherche à envoyer un email HTML avec images imbriquées avec
MIME::Lite et avec une pièce jointe au format .txt
Tout marche mais la piéce jointe au format n'apparait pas à cause de
Type =>'multipart/related'
qq a-t-il une solution ?
code :
#############################################
#!/usr/bin/perl
use MIME::Lite;
use strict;
$msg = MIME::Lite->new(
From =>'xxxx@orange.fr',
To =>'xxxxx@orange.fr',
Subject =>'Envoi de l\'email via Perl!',
Type =>'multipart/related',
);
$msg->attr("content-type.charset" => "iso-8859-1");
$msg->attach(Type => 'text/html',
Data => qq{
<body>
<BR>
<img src="cid:header.jpg">
<BR>
<div style="width: 660px; font-family: Verdana; font-size:
11px; padding: 20px 10px 20px 10px;">
<div style="margin-left: 30px; margin-right: 60px;">
<div style='font-family: Verdana; font-size: 12px; font-weight:
bold; color: #628ED3; padding: 10px 0px 15px 0px; margin: 10px 0px
5px
0px; border-bottom: 1px solid #628ED3;'>BackUp test test
XXX</div><div style='font-family: Verdana; font-size: 10px; padding:
0px
0px 15px 0px; margin: 0px 0px 5px 0px; border-bottom: 1px solid
#628ED3;'>BackUp ok voir le document joint.</div>
<BR>
<img src="cid:footer.jpg">
<BR>
</body>
}
);
$msg->attach
(
Type => 'image/jpg',
Id =>'footer.jpg',
Path => 'footer.jpg'
);
$msg->attach(
Type => 'image/jpg',
Id => 'header.jpg',
Path => 'header.jpg'
);
# piece jointe au format txt
$msg->attach(Type => 'application/txt',
Path => 'BackUp_Database.log',
Filename => 'BackUp_Database.log',
);
$msg->send('smtp', 'xxx.xxx.xx.xx');
#########################################
Merci,
JPC

Poser une question


jpc
À première vue, et sans vérification, je pense qu'il faut imbriquer deux
niveaux : du multipart/mixed au niveau le plus haut avec une première
partie contenant la pièce jointe et une deuxième partie qui sera du
multipart/related (c'est là qu'est l'imbrication) contenant elle-même le
HTML et ses images.
--
Paul Gaborit - Perl en français -
Utiliser Email::MIME::CreateHTML + Template ?
Je peux envoyer un exemple au besoin.
--
freddy <point> dsx <arobase> free <point> fr
##############################################
Ok,
Merci Freddy pour de ta réponse.
Je suis intéressé par l'exemple merci de me l'envoyer.
__________________________________________________
Suite à la 1ere réponse de Paul Gaborit, j'ai fait une recherche sur
le Net , obtenu une piste :
http://www.perlmonks.org/?node_id5240
Et trouvé une solution.
Voici le code qui fonctionne
########################################################
#!/usr/bin/perl
use MIME::Lite;
use strict;
my $msg = MIME::Lite->new(
From =>'',
To =>'',
Subject =>'Envoi de l'email via Perl!',
Type =>'multipart/mixed',
);
#$msg->attr("content-type.charset" => "iso-8859-1");
my $body = MIME::Lite->new (
Type =>'multipart/related',
);
$body->attach(Type => 'text/html',
Data => qq{
<body>
<BR>
<BR>
<div style="width: 660px; font-family: Verdana; font-size:
11px; padding: 20px 10px 20px 10px;">
<div style="margin-left: 30px; margin-right: 60px;">
<div style='font-family: Verdana; font-size: 12px; font-weight:
bold; color: #628ED3; padding: 10px 0px 15px 0px; margin: 10px 0px
5px
0px; border-bottom: 1px solid #628ED3;'>BackUp test test
XXX</div><div style='font-family: Verdana; font-size: 10px; padding:
0px
0px 15px 0px; margin: 0px 0px 5px 0px; border-bottom: 1px solid
#628ED3;'>BackUp ok voir le document joint.</div>
<BR>
<BR>
</body>
}
);
$body->attach
(
Type => 'image/jpg',
Id =>'footer.jpg',
Path => 'footer.jpg'
);
$body->attach(
Type => 'image/jpg',
Id => 'header.jpg',
Path => 'header.jpg'
);
# Attach the "body" part to the original message
$msg->attach($body);
# piece jointe au format txt
$msg->attach(Type => 'application/txt',
Path => 'BackUp_Database.log',
Filename => 'BackUp_Database.log',
);
$msg->send('smtp', 'xxx.xxx.xx.xx')