Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 9th, 2013, 07:03 AM
redstar redstar is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 679 redstar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
Send a message via ICQ to redstar Send a message via AIM to redstar Send a message via MSN to redstar Send a message via Yahoo to redstar
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.

Reply With Quote
  #2  
Old March 9th, 2013, 09:14 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,653 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 7 h 15 m 4 sec
Reputation Power: 1170
Does your smtp server require authentication?

Code:
MIME::Lite->send('smtp', $mail_host, Timeout=>60,
                                     AuthUser=>$user,
                                     AuthPass=>$pass
);

Reply With Quote
  #3  
Old March 9th, 2013, 10:14 AM
redstar redstar is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 679 redstar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
Send a message via ICQ to redstar Send a message via AIM to redstar Send a message via MSN to redstar Send a message via Yahoo to redstar
Yes, but it connects to the local smtp server, not to the remote one.

Reply With Quote
  #4  
Old March 9th, 2013, 10:43 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,653 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 7 h 15 m 4 sec
Reputation Power: 1170
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.

Reply With Quote
  #5  
Old March 9th, 2013, 11:17 AM
redstar redstar is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 679 redstar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
Send a message via ICQ to redstar Send a message via AIM to redstar Send a message via MSN to redstar Send a message via Yahoo to redstar
The mailserver is the remote server, but it requires to authenticate to local smtp server. Is it a filter required by EXIM?

Reply With Quote
  #6  
Old March 9th, 2013, 11:42 AM
redstar redstar is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 679 redstar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 15 h 14 m 40 sec
Reputation Power: 10
Send a message via ICQ to redstar Send a message via AIM to redstar Send a message via MSN to redstar Send a message via Yahoo to redstar
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > MIME::Lite send emails from a remote server

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap