Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: Send Email With Picture Embedded in Body of Email

by jeffenstein (Hermit)
on Sep 10, 2020 at 15:51 UTC ( [id://11121560]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Send Email With Picture Embedded in Body of Email
in thread Send Email With Picture Embedded in Body of Email (SOLVED)

Have you tried building the message with MIME::Lite, and converting it to a string to send with Net::SMTPS?

Borrowing from afoken's post:

$msg = MIME::Lite->new( To =>'you@yourhost.com', Subject =>'HTML with in-line images!', Type =>'multipart/related' ); $msg->attach( Type => 'text/html', Data => qq{ <body> Here's <i>my</i> image: <img src="cid:myimage.gif"> </body> }, ); $msg->attach( Type => 'image/gif', Id => 'myimage.gif', Path => '/path/to/somefile.gif', ); $msg->send();

But replacing $msg->send(); with $smtp->datasend($msg->as_string).

In practice it might be more complicated since you will have to check for lines with a single period (untested):

$smtp->datasend( join "\n", map { $_ eq "." ? ".." : $_ } split "\n", $msg->as_string );

Replies are listed 'Best First'.
Re^5: Send Email With Picture Embedded in Body of Email
by roho (Bishop) on Sep 10, 2020 at 20:58 UTC
    Thank you jeffenstein! That worked perfectly, and it worked without the need of the "join, map, split" code. My final version of the code segment for an embedded image in the email body (while still using "Net::SMTPS") is shown below:

    ############################################################## # Email - body (embedded image) ############################################################## $smtp->datasend("--$boundary\n"); my $msg = MIME::Lite->new( To =>'tester@hotmail.com', Subject =>'HTML with Embedded Image', Type =>'multipart/related' ); $msg->attach( Type => 'text/html', Data => qq{ <body> <img src="cid:mypicture"> </body> }, ); $msg->attach( Type => 'image/jpeg', Id => 'mypicture', Path => 'test.jpg', ); $smtp->datasend( $msg->as_string );

    "It's not how hard you work, it's how much you get done."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121560]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-18 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found