What I'm trying to understand here is what should we put in the from option in this Sendmail snippet. If I'm running the script from my local windows machine, what can i do to send the mail?
use Mail::Sendmail;
sendmail(
From => 'sender#somewhereelse.com',
To => 'recipient#somewhere.com',
Subject => 'some subject',
Message => "body of the message",
);
Under the assumption that you're using SMTP to send mail,
unshift #{$Mail::Sendmail::mailcfg{'smtp'}} , 'my.mail.server';
you can put in from field anything what would you put in Thunderbird/Outlook client.
Related
I am trying to send my first email (from a windows machine) with Perl, but I am getting an error:
SMTP Failed to connect to mail server: at emailer2.pl line 18 (msg->send;)
I am totally new to Perl so any help would be greatly appreciated. Has anyone encountered this problem before? I have searched for the error but I had no luck finding my exact problem.
Thanks so much for your help!
CODE:
#!/usr/bin/perl
use MIME::Lite;
$to = 'myemail#gmail.com';
$cc = 'myemail#gmail.com';
$from = 'myemail#gmail.com';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc => $cc,
Subject => $subject,
Data => $message
);
$msg->send;
print "Email Sent Successfully\n";
It means you don't have a mail server running on your machine. You need to install one and make sure it is running.
You may also use another mail server setting default parameters before sending the message
MIME::Lite->send('smtp', "smpt.example.org", Timeout=>60, SSL=>1,
AuthUser=>"myself", AuthPass=>"mysecret");
Take a look at MIME::Lite sending section.
I have followed this link and here is my php code. My issue is that I have tried so many times with this and didn't receive any emails. Could you please point out what went wrong? Thank you
http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/
if($result)
{
$to = $email;
$subject = "Your comfirmation email";
$header = "from: your name <your email>";
$message = "Thank you for registering with us. You can now login to your account";
if(mail($to, $subject,$header,$message))
{
echo 'Your Confirmation Email Has Been Sent To Your Email Address.
Click here to Login';
}
else
{
echo 'Cannot send Confirmation link to your e-mail address.
Click here to Register';
}
}
Do you have a mail server configured on your system?
Windows does not come with a mail server like *nix. The simple answer is to use a library like phpMailer, which allows you to use a gmail /yahoo /etc mail account to send you email.
I am unable to send a mail using MIME::Lite. While sending from my desktop it will through the below errors.
Error: "SMTP Failed to connect to mail server: Bad file descriptor"
I am using the below mentioned code.
use strict;
use MIME::Lite;
use Net::SMTP;
my $from_address = "no-reply#host.com";
my $to_address = "madhan#host.com";
my $cc_address = "madhan#host.com";
my $subject = "Test mail";
my $message_body = "Madhan test mail";
my $namer="madhankumar";
my $regards="Madhan M";
print " Sending mail from $from_address to $to_address \n";
my $person_name=ucfirst($namer).",";
my $mail_host = 'mail1.somehost.com';
my $msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Cc => $cc_address,
Subject => $subject,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";
$msg->attach (
Type => 'TEXT',
Data => "Dear $person_name\n\n".$message_body."\n\nRegards,\n$regards"
) or die "Error adding the text message part: $!\n";
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;
The above code is working fine while the mail server is connected with LAN. While using the code in remote system the error has been thrown as mentioned in below
"SMTP Failed to connect to mail server: Bad file descriptor".
May I know the reason.. Is the code run in remote system. If not what are the change I have made the code.. Please share your solutions....
Thanks in advance...
Note: I am developing this in Windows XP
The variables do not contain what you think they contain. If you had switched on warnings, you would have noticed this on your own.
$ perl -e'use warnings; my $from_address = "no-reply#host.com";'
Possible unintended interpolation of #host in string at -e line 1.
Name "main::host" used only once: possible typo at -e line 1.
The remedy is to use single quotes to delimit those strings.
I'm trying to send emails out using MIME::Lite with authentication.
Here's the code snippet I am trying:
#!/usr/bin/perl
use strict;
use DBI;
use lib '/theannealing.com/perl/';
use MIME::Lite;
use MIME::Base64;
use Authen::SASL;
my $recipient = 'recipient#email.com';
my $mailman = 'sender#email.com';
my $cc_recipient = 'ccrecipient#email.com';
my $subject = 'Subject';
my $email_message = "Message";
my ($user,$pass) = ("username","password");
MIME::Lite->send('smtp','smtp.server:port',AuthUser=>$user, AuthPass=>$pass);
my $email = new MIME::Lite(From => $mailman,To => $recipient,Cc => $cc_recipient,Subject => $subject,Data => "Data",Type => "multipart/mixed");
$email->attach(Type => 'TEXT', Data => "$email_message");
$email->send();
When I execute the script, I get this error message:
Cannot find a SASL Connection library at /usr/lib/perl5/5.8.8/Net/SMTP.pm line 143
I tried searching the error message and couldn't find any worth-while explanations and/or solutions to the problem with relevance to usage with MIME::Lite
Does anyone know what's wrong or what's producing that error message?
UPDATE
Emailing via php using the mail() function works fine from a web browser, but does not work from the command line
You need to reinstall Authen::SASL - it was installed incorrectly. Do this as root from command line:
cpan GBARR/Authen-SASL-2.15.tar.gz
I need a tiny Windows script to send a 1 line email to Gmail accounts. I have tried many utilities that claim to do this such as BLAT, but none work. The script will be executed inside a batch file if certain conditions are met. Script can be in Perl, Python, VBScript, Java, it does not matter as long as it executes from a batch file. Please only answer if you have tried your solution by sending an email to a Gmail account from either a Gmail, Hotmail or Yahoo email account. The account I am using by default is Gmail, so I am sending from a Gmail account to a Gmail account.
Blat lets you send e-mails directly from batch files:
blat.exe - -f from#example.com -to to#gmail.com -s Subject -body "Text body" ^
-server smtp.example.com:25 -u username -pw password
But it seems that Blat doesn't support SSL, so to make it work with the Gmail you need an additional tool called Stunnel (see here and here).
Anyway, you should be able to send an e-mail via GMail from VBScript using the Collaboration Data Objects (CDO) COM API:
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf
' E-mail properties
Set oMsg = CreateObject("CDO.Message")
oMsg.From = "from#gmail.com" ' or "Sender Name <from#gmail.com>"
oMsg.To = "to#gmail.com" ' or "Recipient Name <to#gmail.com>"
oMsg.Subject = "Subject"
oMsg.TextBody = "Text body"
' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver") = "smtp.gmail.com"
oConf.Fields(schema & "smtpserverport") = 465
oConf.Fields(schema & "sendusing") = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic
oConf.Fields(schema & "smtpusessl") = True
oConf.Fields(schema & "sendusername") = "from#gmail.com"
oConf.Fields(schema & "sendpassword") = "sender_password"
oConf.Fields.Update
oMsg.Send
Edit: Added the lacking sendusing parameter so it should work fine now.
See here for more CDO examples.
Have a look at this script on perlmonks which details IMAP access on a GMail account. The post covers everything you need to login into a GMail account through Perl.
Alternatively you could try the Mail::Webmail::Gmail module in CPAN. From the looks of it the module lets you skip most of the intricate details concerning connecting and authenticating with the mail server leaving you with something as simple as -
my $gmail = Mail::Webmail::Gmail->new( username => 'username', password => 'password', );
$gmail->send_message( to => 'user#domain.com', subject => 'Test Message', msgbody => 'This is a test.' );
There's also Email::Send::Gmail in case you need to 'only' send emails from a Gmail account.
#!c:/Python/python.exe -u
import libgmail
ga = libgmail.GmailAccount("username#gmail.com", "password")
ga.login()
msg=libgmail.GmailComposedMessage("friend#gmail.com", "SubjectHere", "BodyHere")
ga.sendMessage(msg)
That should run on Windows using python. Make sure you change the shebang at the top to point to your python installation. Other than that, just enter your name and password, along with the email you want to send.
If you need just to send to GMail using some SMTP, use MIME::Lite Perl module in SMTP mode - I use it to send notifications to my GMail account.
In Linux (I'm not sure what environment you're on) you can use mail:
some_command| mail foo#gmail.com bar#gmail.com -s "subject"