mail::sendmail client not authenticated error - perl

I am trying to use the Mail::Sendmail package to send a mail. Yet I am getting this error:
MAIL FROM: error (530 5.7.57 SMTP; Client was not authenticated to
send anonymous mail during MAIL FROM)
I suspect this has something to do with my santaclaus#christmas.com mail ?
use Mail::Sendmail qw(sendmail %mailcfg);
unshift #{$Mail::Sendmail::mailcfg{'smtp'}} , 'smtp.office365.com:587';
%mail = ( To => 'existingmail#outlook.com',
From => 'santaclaus#christmas.com',
Message => "Time for surprises and gifts is approaching..."
);
sendmail(%mail) or die $Mail::Sendmail::error;
print "OK. Log says:\n", $Mail::Sendmail::log;

It seems that smtp.office365.com requires SMTP AUTH command (SMTP Authentication) to accept email for sending.
Mail::Sendmail DOES NOT support SMTP authentication.
http://search.cpan.org/~mivkovic/Mail-Sendmail-0.79/Sendmail.pm
LIMITATIONS
[...]
No suport for the SMTP AUTH extension.

Related

PHPMailer not able to send send email with ec2

I'm using PHPmailer to send account verification mail, I'm using AWS ec2 instance, however, that mailer is working fine in localhost but when I upload that to server emails are not going,
at first, i used SendGrid credentials to send emails, failed, then tried Gmail SMTP, failed, and somewhere I read that ec2 can't send emails, then I created SES also, still can't able to send.
searched on the web abt that but no answers are fixing my problem,
in localhost, in can send emails with the same code and with SendGrid of Gmail credentials, why I can't send with the server?
my PHP mailer code is:
$sub = "Thankyou For registration! Confirm Your mail to Login";
$mailBody = "<h1>You are successfully registered<br />Visit site to login</h1>";
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "tls://email-smtp.us-east-1.amazonaws.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = "smtp_username"; // SMTP username
$mail->Password = "smtp_password"; // SMTP password
// $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom("my_mail_id#gmail.com", "SMTP_REPLAY_NAME");
$mail->addReplyTo("my_mail_id#gmail.com", "SMTP_REPLAY_NAME");
$mail->addAddress("recipient_mail_id#gmail.com"); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $sub;
$mail->Body = $mailBody;
if(!$mail->send()) {
echo 'Message could not be sent.';
} else {
echo 'Message has been sent';
}
it shows Message has been sent but I cant receive emails, checked in spam folder also, no clue of mail!
even I have openSSL certificate also! opened SMTP port for both inbound and outbound in security group of ec2, everything working fine but PHPMailer!
Get your protocols straight. In the Host you're specifying tls, but telling it to connect to Port = 465, which will not work with TLS. Either change your Port to 587 (preferred) or change your encryption method to ssl. Enabling debug output (SMTPDebug = 2) will let you in on what's happening in the conversation with the server.
A perusal of the troubleshooting guide would probably help.

how to send mail using perl with attachement?

I've try to send mail using perl with attachment I've tried with Email::Stuff and MIME::Lite,during run time i got some error as Authentication failed or server not connected can anybody help me?
corresponding code is:
use MIME::Lite;
use Net::SMTP;
### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'atme04#gmail.com';
my $to_address = 'thiyagu040#gmail.com';
my $mail_host = 'smtp.gmail.com';
### Adjust subject and body message
my $subject = 'A message with 2 parts ...';
my $message_body = "Here's the attachment file(s) you wanted";
my $your_file_zip = 'my.zip';
$msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";
MIME::Lite->send('smtp', 'smtp.gmail.com' ,
Port =>465 ,
Timeout=>320 ,
Debug => 1 ,
Hello => $mail_host,
User => $from_address,
Password => 'Thiyagu.04' );
#$mime_msg->send() or die "Error sending message: $!\n";
#MIME::Lite->send('smtp',$mail_host,AuthUser=> $from_address, AuthPass=>"apssword");
$msg->send();
error message is;
SMTP Failed to connect to mail server: A connection attempt failed because the connected party did not properly respond aft
er a period of time, or established connection failed because connected host has failed to respond.
at mail.pl line 54.
thanks in advance
The error message seems pretty clear to me. The problem is with your connection to the mail server - so changing the module that you're using is unlikely to achieve anything useful. I don't know enough about Gmail's server settings to comment on what the problem is, but this page has some suggestions that you might follow. Specifically, you could check that the Gmail account has 'allow authentication' turned on and that your mail client (the Perl program) is using SSL for the connection.
Also, this might be easier if you used an email that was specifically designed for use with Gmail. Email::Send::SMTP::Gmail looks tailor-made for your requirements.

I do i setup sendmail in php.ini on wampserver 2.1 to post form data on local machine ?

I have created some forms using zendframework on my local machine that send the form content via email.
I would like to test the functionality locally and have read some posts regarding configuring the php.ini file to do this but not sure which is the correct method ?
can anyone help me with this, many thanks
On Windows you will have to use SMTP to send the message. There is a drop in fake sendmail for Windows but it still requires an SMTP server.
You could use your ISP's sendmail server if they offer one, or you can set one up on the local machine. 1, 2, 3, 4
Since you are using Zend Framework, you can alternatively use Zend_Mail to send through an SMTP server (Zend_Mail can also use sendmail, but since it isn't configured, you can't use that transport). In that case see Sending via SMTP, SMTP Authentication, and Securing SMTP Transport.
Here is some sample code for sending an SMTP message with AUTH and TLS security.
<?php
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
$config = array('ssl' => 'tls',
'port' => '465', // 25 if no ssl
'auth' => 'login',
'username' => 'user',
'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.example.com', $config);
$mail = new Zend_Mail();
$mail->addTo('user#domain')
->setSubject('Mail Test')
->setBodyText("Hello,\nThis is a Zend Mail message...\n")
->setFrom('sender#domain');
try {
$mail->send($transport);
echo "Message sent!<br />\n";
} catch (Exception $ex) {
echo "Failed to send mail! " . $ex->getMessage() . "<br />\n";
}
Also note, your ISP may not require you to auth at all if you are sending from one of their IP addresses, but you probably do have to authenticate with your username and password, in which case you will want to use TLS.

SMTP Authentication problem

I'm writing a simple mail client in Perl, that uses SMTP to log in a Mail server, and from there sends a mail to another E-mail address (on different host). I use raw SMTP commands, because strawberry perl doesn't come with SASL.pm which is needed in order to authenticate. However, when the script tries to authenticate itself, it fails. I tried 'AUTH LOGIN' and 'AUTH PLAIN' mechanism but no luck. Here is an example:
EHLO example.com
AUTH LOGIN
YWxwaGE=
cGFzc3dvcmQ=
MAIL FROM:<alpha#example.com>
RCPT TO:<beta#betadomain.com>
DATA
Subject: sample message
From: alpha#example.com
To: beta#betadomain.com
Greetings,
Typed message (content)
Goodbye.
.
QUIT
EOT
"YWxwaGE=", "cGFzc3dvcmQ=" are the user and password encoded in Base64. Whatever I submit the server always complains that either the username or the password is wrong. What do I do wrong?
Why not just install a module that supports SMTP with SASL? One of the advantages of Strawberry Perl is that you can easily install modules from CPAN.
For example, Email::Simple and Email::Sender:
use strict;
use warnings;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
use Email::Sender::Transport::SMTP;
my $email = Email::Simple->create(
header => [
To => 'beta#betadomain.com',
From => 'alpha#example.com',
Subject => "sample message",
],
body => "Greetings,\nTyped message (content)\nGoodbye.\n",
);
my $transport = Email::Sender::Transport::SMTP->new({
host => 'smtp.example.com',
sasl_username => 'foo',
sasl_password => 'bar',
});
sendmail($email, { transport => $transport });

How do you fix 550 must be authenticated sending Mail using Grails?

I'm using Grails Mail plugin and trying to send email and keep getting:
Error 500: Executing action [sendInvite] of controller
[RegisterController] caused exception: Failed messages:
javax.mail.SendFailedException: Invalid Addresses; nested exception
is: com.sun.mail.smtp.SMTPAddressFailedException: 550 must be
authenticated
I'm properly following the instructions at: http://www.grails.org/Mail+plugin
The mail server is returning an error when you try to send out the mail. 550 is a generic SMTP failure code; in this case it looks like you are missing a username and password. Some SMTP servers to not require authentication but most do, especially if they're publicly available on the internet. It's also possible that your SMTP server requires an SSL connection and you're connecting with an unsecured socket.
The example config for gmail shows how to set all the mail server authentication options in Config.groovy:
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "youracount#gmail.com"
password = "yourpassword"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
Add "mail.debug": "true" to props to turn on JavaMail debugging to get a better picture of what is happening before the failure.
In my case the 550 error was caused by me having accidentally selected and IMAP account as the default account but sending emails from my Outlook Connector Account (which has no authentication settings to make).
I changed the Outlook Connector Account to default. Resent the emails and no errors.
So check that the correct email account is set up as the default also