Email#

NAME#

Kernel::System::Email - to send email

DESCRIPTION#

Global module to send email via sendmail or SMTP.

PUBLIC INTERFACE#

new()#

Don’t use the constructor directly, use the ObjectManager instead:

my $EmailObject = $Kernel::OM->Get('Kernel::System::Email');

Send()#

To send an email without already created header:

my $Sent = $SendObject->Send(
    From          => 'me@example.com',
    To            => 'friend@example.com',                         # required if both Cc and Bcc are not present
    Cc            => 'Some Customer B <customer-b@example.com>',   # required if both To and Bcc are not present
    Bcc           => 'Some Customer C <customer-c@example.com>',   # required if both To and Cc are not present
    ReplyTo       => 'Some Customer B <customer-b@example.com>',   # not required, is possible to use 'Reply-To' instead
    Subject       => 'Some words!',
    Charset       => 'iso-8859-15',
    MimeType      => 'text/plain', # "text/plain" or "text/html"
    Body          => 'Some nice text',
    InReplyTo     => '<somemessageid-2@example.com>',
    References    => '<somemessageid-1@example.com> <somemessageid-2@example.com>',
    Loop          => 1, # not required, removes smtp from
    CustomHeaders => {
        X-OTRS-MyHeader => 'Some Value',
    },
    Attachment => [
        {
            Filename    => "somefile.csv",
            Content     => $ContentCSV,
            ContentType => "text/csv",
        },
        {
            Filename    => "somefile.png",
            Content     => $ContentPNG,
            ContentType => "image/png",
        }
    ],
    EmailSecurity => {
        Backend     => 'PGP',                       # PGP or SMIME
        Method      => 'Detached',                  # Optional Detached or Inline (defaults to Detached)
        SignKey     => '81877F5E',                  # Optional
        EncryptKeys => [ '81877F5E', '3b630c80' ],  # Optional
    }
);

my $Sent = $SendObject->Send(                   (Backwards compatibility)
    From       => 'me@example.com',
    To         => 'friend@example.com',
    Subject    => 'Some words!',
    Charset    => 'iso-8859-15',
    MimeType   => 'text/plain', # "text/plain" or "text/html"
    Body       => 'Some nice text',
    InReplyTo  => '<somemessageid-2@example.com>',
    References => '<somemessageid-1@example.com> <somemessageid-2@example.com>',
    Sign       => {
        Type    => 'PGP',
        SubType => 'Inline|Detached',
        Key     => '81877F5E',
        Type    => 'SMIME',
        Key     => '3b630c80',
    },
    Crypt => {
        Type    => 'PGP',
        SubType => 'Inline|Detached',
        Key     => '81877F5E',
    },
);

if ($Sent) {
    print "Email queued!\n";
}
else {
    print "Email not queued!\n";
}

SendExecute()#

Really send the mail

my $Result = $SendObject->SendExecute(
    From                   => $RealFrom,
    To                     => \@ToArray,
    Header                 => \$Param{Header},
    Body                   => \$Param{Body},
    CommunicationLogObject => $CommunicationLogObject,
);

# or

my $Result = $SendObject->SendExecute(
    From                   => $RealFrom,
    To                     => $To, # can be a string with comma separated mail addresses
    Header                 => \$Param{Header},
    Body                   => \$Param{Body},
    CommunicationLogObject => $CommunicationLogObject,
);

This returns something like:

$Result = {
    Success      => 0|1,
    ErrorMessage => '...', # In case of failure.
}

Check()#

Check mail configuration

my %Check = $SendObject->Check();

Bounce()#

Bounce an email

$SendObject->Bounce(
    From  => 'me@example.com',
    To    => 'friend@example.com',
    Email => $Email,
);