[SOLVED] Sending Emails with PNG and PDF Attachment

Moderator: crythias

Locked
thr
Znuny newbie
Posts: 24
Joined: 10 Apr 2014, 13:18
Znuny Version: 3.3.4

[SOLVED] Sending Emails with PNG and PDF Attachment

Post by thr »

Hello together,

i have a question regarding sending Emails from a perl module in OTRS. I am trying to send a mail with 2 attachements, one being a png-image and a pdf-document. I did a bit of research and also found one code-example in the OTRS-API. I got so far, that sending the email works just fine and also there looks to be an attachement (i started with the png image), but the problem is, this attachement is only 1kb of size and empty image file. Heres the code i am using:

Code: Select all

        
        my $mailobject = $SendObject->Send(
            From          => '....',
            To            => '...',
            Subject       => '',
            Charset       => 'utf-8',
            MimeType      => 'text/plain',
            Body          => 'my text',
            Attachment   => [
                {
                    Filename    => "testfile.png",
                    Content     => "empty",
                    ContentType => "image/png",
                }
            ],
	...
        );
Like i said, sending the email works without any problems, just the attachement doesn't. I think the problem is the "Content"-Parameter in the attachments-section, i don't really know what i have to put in there. The OTRS Api puts a variable "Content => $ContentPNG" in, but i don't have this variable, and also don't know what is in there. Can anyone give me a hint?

And one further question what would be the Content and the ContentType for a pdf-attachment? Is the content-type "application/pdf"??
Last edited by thr on 13 Mar 2015, 11:41, edited 1 time in total.
Version: OTRS version 3.3.4 mit ITSM und KIX4OTRS
OS: Debian6 x64
Datenbank: MySQL
Webserver: Apache2
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Sending Emails with PNG and PDF Attachment

Post by reneeb »

You have to put the content of the file to the Content key.

So this should help

Code: Select all

        my $PNGContent = $Self->{MainObject}->FileRead(
            Location          => '/path/to/the/testfile.png',
            Mode          => 'binmode',
        );     
        my $mailobject = $SendObject->Send(
            From          => '....',
            To            => '...',
            Subject       => '',
            Charset       => 'utf-8',
            MimeType      => 'text/plain',
            Body          => 'my text',
            Attachment   => [
                {
                    Filename    => "testfile.png",
                    Content     => ${$PNGContent},
                    ContentType => "image/png",
                }
            ],
   ...
        );
The same applies for the PDF attachment. The content-type is - as you said - application/pdf
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
thr
Znuny newbie
Posts: 24
Joined: 10 Apr 2014, 13:18
Znuny Version: 3.3.4

Re: Sending Emails with PNG and PDF Attachment

Post by thr »

Thanks very much, thats sounds good, will try it as soon as possible
Version: OTRS version 3.3.4 mit ITSM und KIX4OTRS
OS: Debian6 x64
Datenbank: MySQL
Webserver: Apache2
thr
Znuny newbie
Posts: 24
Joined: 10 Apr 2014, 13:18
Znuny Version: 3.3.4

Re: Sending Emails with PNG and PDF Attachment

Post by thr »

Works like a charm, thank you.
Version: OTRS version 3.3.4 mit ITSM und KIX4OTRS
OS: Debian6 x64
Datenbank: MySQL
Webserver: Apache2
Locked