The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
MIME::Lite send emails from a remote server
Discuss MIME::Lite send emails from a remote server in the Perl Programming forum on Dev Shed. MIME::Lite send emails from a remote server Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 9th, 2013, 07:03 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 679
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
|
|
|
MIME::Lite send emails from a remote server
Hello,
I am using the following code to send emails using MIME::Lite
Code:
use MIME::Lite;
use Net::SMTP;
### 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,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";
### Add the text message part
$msg->attach (
Type => 'TEXT',
Data => $message_body
) or die "Error adding the text message part: $!\n";
### Add the GIF file
$msg->attach (
Type => 'image/gif',
Path => $my_file_gif,
Filename => $your_file_gif,
Disposition => 'attachment'
) or die "Error adding $file_gif: $!\n";
### Add the ZIP file
$msg->attach (
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);
$msg->send;
It doesn't connect to the specified $mail_host, it connects to local SMTP server
Code:
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?
Code:
MIME::Lite->send('smtp', $mail_host, Timeout=>60,
AuthUser=>$user,
AuthPass=>$pass
);
|

March 9th, 2013, 10:14 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 679
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
|
|
|
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
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 679
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
|
|
|
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
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 679
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|