March 9th, 2013, 07:03 AM
MIME::Lite send emails from a remote server
I am using the following code to send emails using MIME::Lite
It doesn't connect to the specified $mail_host, it connects to local SMTP server
### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'martin dot zahn at akadia dot ch';
my $to_address = 'martin dot zahn at akadia dot ch';
my $mail_host = 'mailhost.domain.com';
### Adjust subject and body message
my $subject = 'A message with 2 parts ...';
my $message_body = "Here's the attachment file(s) you wanted";
### Adjust the filenames
my $my_file_gif = 'my_file.gif';
my $your_file_gif = 'your_file.gif';
my $my_file_zip = 'my_file.zip';
my $your_file_zip = 'your_file.zip';
### Create the multipart container
$msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
) or die "Error creating multipart container: $!\n";
### Add the text message part
Type => 'TEXT',
Data => $message_body
) or die "Error adding the text message part: $!\n";
### Add the GIF file
Type => 'image/gif',
Path => $my_file_gif,
Filename => $your_file_gif,
Disposition => 'attachment'
) or die "Error adding $file_gif: $!\n";
### Add the ZIP file
Type => 'application/zip',
Path => $my_file_zip,
Filename => $your_file_zip,
Disposition => 'attachment'
) or die "Error adding $file_zip: $!\n";
### Send the Message
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
220-local.smtp ESMTP Exim 4.80 #2 Sat, 09 Mar 2013 14:44:11 +0200
MIME::Lite::SMTP=GLOB(0xd2d8a0)<<< 220-We do not authorize the use of this system to transport unsolicited,
MIME::Lite::SMTP=GLOB(0xd2d8a0)<<< 220 and/or bulk e-mail.
March 9th, 2013, 09:14 AM
Does your smtp server require authentication?
MIME::Lite->send('smtp', $mail_host, Timeout=>60,
March 9th, 2013, 10:14 AM
Yes, but it connects to the local smtp server, not to the remote one.
March 9th, 2013, 10:43 AM
It will connect to the server you specify.
Your send statement is specifying $mail_host (I'm assuming form your code that is a remote server). If that server requires authentication, then you'll need to pass that info in the send statement like I showed.
If that server is on your local network, then the email should go through once you authenticate; assuming that the server is setup correctly. If that server is not local then it still may fail even after authenticating if they don't allow cross domain relay.
March 9th, 2013, 11:17 AM
The mailserver is the remote server, but it requires to authenticate to local smtp server. Is it a filter required by EXIM?
March 9th, 2013, 11:42 AM
I think this is the flow:
mailx → /usr/bin/sendmail → local MTA → Gmail or ISP/work servers → recipient MTA → recipient inbox
I need it to be:
app → Gmail or ISP/work servers → recipient MTA → recipient inbox