Unverified Commit e80dbf41 authored by Kenny's avatar Kenny
Browse files

Fix SMTP email and improve documentation

My email provider rejects emails that don't contain the MIME-Version and Date
headers with "5.7.1 Spam message rejected", so this adds those.

Also, the example email configuration file was not clear enough for me when it
comes to what values I could pass (for example, to authenticate), so I added
a comment linking to the docs.

Since the documented minimum Perl version in doc/setup.md is 5.40, I
modified the minimum version in lib/Travelynx/Helper/Sendmail.pm in order to
use try/catch.
parent 7fc66759
Loading
Loading
Loading
Loading
+3 −0
Changes for cpanfile: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -29,3 +29,6 @@ requires 'Travel::Status::DE::HAFAS', '>= 6.20';
requires 'Travel::Status::DE::IRIS';
requires 'UUID::Tiny';
requires 'XML::LibXML';

requires 'MIME::Base64';
requires 'Authen::SASL';
+5 −2
Changes for examples/docker/email-transport.sh: 5 added lines, 2 removed lines.
Original line number Diff line number Diff line
#!/bin/sh

export EMAIL_SENDER_TRANSPORT=SMTP
export EMAIL_SENDER_TRANSPORT_HOST=smtp.example.com
export EMAIL_SENDER_TRANSPORT_PORT=25
# [INFO] You can set any of the attributes found here:
# https://metacpan.org/pod/Email::Sender::Transport::SMTP#ATTRIBUTES
# For example, the following lines set the attributes host and port
export EMAIL_SENDER_TRANSPORT_host=smtp.example.com
export EMAIL_SENDER_TRANSPORT_port=25
+14 −4
Changes for lib/Travelynx/Helper/Sendmail.pm: 14 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -6,11 +6,13 @@ package Travelynx::Helper::Sendmail;

use strict;
use warnings;
use feature 'try';

use 5.020;
use 5.040;

use DateTime;
use Encode                qw(encode);
use Email::Sender::Simple qw(try_to_sendmail);
use Email::Sender::Simple qw(sendmail);
use MIME::Entity;

sub new {
@@ -26,10 +28,12 @@ sub custom {
		To             => $to,
		From           => $self->{config}{from},
		Subject        => encode( 'MIME-Header', $subject ),
		Type     => 'text/plain',
		Type           => 'text/plain;format=flowed',
		Charset        => 'UTF-8',
		Encoding       => 'quoted-printable',
		Data           => encode( 'utf-8', $body ),
		"MIME-Version" => '1.0',
		"Date"         => DateTime->now->strftime("%a, %d %b %Y %H:%M:%S %z"),
	);

	if ( $self->{config}->{disabled} ) {
@@ -39,7 +43,13 @@ sub custom {
		return 1;
	}

	return try_to_sendmail($reg_mail);
	try {
		return sendmail($reg_mail);
	}
	catch ($e) {
		$self->{log}->error("Sendmail.pm: sendmail error ${e}");
		return 0;
	}
}

sub age_deletion_notification {