Add a warning when an email exceeds 10Mb

pull/2901/head
Isaac Connor 2020-03-28 11:19:06 -04:00
parent 599960ef05
commit 38c018ed18
1 changed files with 25 additions and 12 deletions

View File

@ -829,14 +829,20 @@ sub sendEmail {
Data => $body
);
### Add the attachments
my $total_size = 0;
foreach my $attachment ( @attachments ) {
Info("Attaching '$attachment->{path}'");
my $size = -s $attachment->{path};
$total_size += $size;
Info("Attaching '$attachment->{path}' which is $size bytes");
$mail->attach(
Path => $attachment->{path},
Type => $attachment->{type},
Disposition => 'attachment'
);
}
if ( $total_size > 10*1024*1024 ) {
Warning('Emails larger than 10Mb will often not be delivered! This one is '.int($total_size/(1024*1024)).'Mb');
}
### Send the Message
if ( $Config{ZM_SSMTP_MAIL} ) {
my $ssmtp_location = $Config{ZM_SSMTP_PATH};
@ -860,20 +866,27 @@ sub sendEmail {
}
} else {
my $mail = MIME::Entity->build(
From => $Config{ZM_FROM_EMAIL},
To => $$filter{EmailTo},
Subject => $subject,
Type => (($body=~/<html/)?'text/html':'text/plain'),
Data => $body
);
From => $Config{ZM_FROM_EMAIL},
To => $$filter{EmailTo},
Subject => $subject,
Type => (($body=~/<html/)?'text/html':'text/plain'),
Data => $body
);
my $total_size = 0;
foreach my $attachment ( @attachments ) {
Info("Attaching '$attachment->{path}'");
my $size = -s $attachment->{path};
$total_size += $size;
Info("Attaching '$attachment->{path}' which is $size bytes");
$mail->attach(
Path => $attachment->{path},
Type => $attachment->{type},
Encoding => 'base64'
);
Path => $attachment->{path},
Type => $attachment->{type},
Encoding => 'base64'
);
} # end foreach attachment
if ( $total_size > 10*1024*1024 ) {
Warning('Emails larger than 10Mb will often not be delivered! This one is '.int($total_size/(1024*1024)).'Mb');
}
$mail->smtpsend(Host => $Config{ZM_EMAIL_HOST}, MailFrom => $Config{ZM_FROM_EMAIL});
}