Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Immediate help needed with adding inline image within email body

Status
Not open for further replies.

mlibeson

Programmer
Mar 6, 2002
311
US
I am trying to send emails to clients and I have some pre-formatted text at the top of the body of the email then I have a digital signature that I need to add before the end of the body of the email.

Please help me get the text and inline image to work correctly. The email is sent but the pre-formatted text is not pre-formatted and image is in the wrong place. Some text is wrapped past the image.

Below is the code I am using:

Code:
$sender = new Mail::Sender {
     smtp => "$smtp",
     auth => 'LOGIN',
     authid => "$ARGV[0]",
     authpwd => "$ARGV[1]",
     keepconnection => 1,
     client => "$smtp",
     fromaddr => "$from",
     from => "$from"
} or die "ERROR with set-up\n";

$Mail::Sender::NO_X_MAILER = 1;

$Mail::Sender::skip_bad_recipients = 1;

$gi = 1;
foreach $code ('AG', 'AD') {
     $msgid = &createmessageid($code,$gi++);
     $to = "$recipient";
     $subject = "Ballot [$msgid]";
     $msg = <<EOT;
<HTML><BODY><PRE>
To whom it may concern,

            We look forward to receiving your statement.

                    Sincerely,

</PRE>
<IMG SRC="cid:tniv">
<PRE>
                                                                        John Doe
</PRE></BODY></HTML>
EOT

     $obj = $sender->OpenMultipart({
          to => "$to",
          subject => "$subject",
          messageid => "$msgid",
          priority => 1,
          confirm => 'delivery',
          type => 'multipart/related'
     });
     if (ref $obj) {
          print STDOUT "Message ", $sender->{messageid}, " pending.\n";
     } else {
          print STDOUT "Message not sent. $obj\n";
     }

     $sender->Body(ctype => 'text/html; charset=us-ascii', msg => "$msg");
     $sender->Attach({
          description => 'NONE',
          ctype => 'image/bmp',
          encoding => 'base64',
          disposition => "inline; filename=\"image.bmp\";\r\nContent-ID: <tniv>",
          file => 'image.bmp'
     });

     $sender->Close();
}

exit(0);

sub createmessageid {
     my ($c, $i) = @_;
     return "MSGT$c$i";
}


Michael Libeson
 
OK.

I changed:
Code:
     $sender->Body(ctype => 'text/html; charset=us-ascii', msg => "$msg");

To:
Code:
     $sender->Body();
     $sender->SendEnc("$msg");

I moved "ctype => 'text/html; charset=us-ascii'" to be in the openmultipart.


This fixes the image and text problem except that my first of 2 emails has a broken image. Help please!




Michael Libeson
 
I found the problem, but I do not know how to resolve it.

Here is the code where the problem is:
Code:
     $obj = $sender->OpenMultipart({
          to => "$to",
          subject => "$subject",
          messageid => "$msgid",
          priority => 1,
          confirm => 'delivery',
          type => 'multipart/related'
     });

The "type" is expressed as 'multipart/related' and works fine for the 2nd email and thereafter, but does not work for the first one. The first somehow gets converted from 'multipart/related' to 'multipart/mixed'. If I replace 'mixed' with 'related', then view the email, it works fine.

Is there anyone that can help?

Thank you.


Michael Libeson
 
OK, there is a bug in the program somewhere. I was able to get around it by changing the following piece of code.

From:
Code:
$sender = new Mail::Sender {
     smtp => "$smtp",
     auth => 'LOGIN',
     authid => "$ARGV[0]",
     authpwd => "$ARGV[1]",
     keepconnection => 1,
     client => "$smtp",
     fromaddr => "$from",
     from => "$from"
} or die "ERROR with set-up\n";

To:
Code:
$sender = new Mail::Sender {
     smtp => "$smtp",
     auth => 'LOGIN',
     authid => "$ARGV[0]",
     authpwd => "$ARGV[1]",
     keepconnection => 1,
     client => "$smtp",
     fromaddr => "$from",
     from => "$from",
     type => 'multipart/related'
} or die "ERROR with set-up\n";

I added one line in order to force the "type":
type => 'multipart/related'


Michael Libeson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top