Postfix & Rails 3.0 ActionMailer: lost connection after STARTTLS - email

I'm using Ruby 1.9.2 and Rails 3.0.4 in development mode and I'm trying to configure it to send emails from the Postfix server installed on the same box (Running Ubuntu 10.04 with the dovecot-postfix package installed) Whenever I attempt to send an email from Rails, it goes through cleanly in Rails but displays an error in the Postfix logs (I've removed domains and IPs from the excerpt below):
Feb 21 04:49:16 alpha postfix/smtpd[9060]: connect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: lost connection after STARTTLS from alpha.mydomain.com[xxx.xxx.xxx.xxx]
Feb 21 04:49:16 alpha postfix/smtpd[9060]: disconnect from alpha.mydomain.com[xxx.xxx.xxx.xxx]
The strange part is that when I connect to the SMTP server from an email client like Thunderbird, it works with no problems.
I know development mode sometimes doesn't allow for sending emails so I added the following to the environments/development.rb file:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
#load mail server settings
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "mail.mydomain.com",
:port => 587,
:domain => 'mydomain.com',
:user_name => 'username',
:password => 'password',
:authentication => 'plain',
:tls => true,
:enable_starttls_auto => true }

If you're just sending email from localhost, then you don't need SMTP and all the authentication issues that come with it. You can simply deliver with sendmail directly.
config.action_mailer.delivery_method = :sendmail

Is it possible that your certificate is not valid, and that Thunderbird falls back to plain SMTP when sending emails? Try disabling TLS in your config.

Related

Unable to submit email on port 465 using Net::SMTP module in Perl

I want to submit email on port 465 of my smtp server using the Net::SMTP module(without using Net::SMTP::SSL) in a perl script from client. On Port 465 of my SMTP server, "submissions" service runs, which understands SMTPS.
I have tried to find the way to do this on google. Then used the Net::SMTP::SSL module to make request on port 465. It works fine.
But the documentation for Net::SMTP::SSL recommends using latest version Net::SMTP instead of using Net::SMTP::SSL.
The document clearly states that
Since Net::SMTP v1.28 (2014-10-08), Net::SMTP itself has support for
SMTP over SSL, and also for STARTTLS. Use Net::SMTP, not
Net::SMTP::SSL.
I have updated Net::SMTP module to the latest version 3.11.
Also the document for Net::SMTP also stated clearly that
With IO::Socket::SSL installed it also provides support for implicit
and explicit TLS encryption, i.e. SMTPS or SMTP+STARTTLS.
The part of my perl script code on client ,relevant to the problem mentioned looks like so:
$smtp = Net::SMTP::SSL->new("$mailserver",
Hello => "$localhostname",
Timeout => 60,
Port => "$port", //Port value is 465
Debug => 1);
$smtp->auth($username, $password);
...Remaining script which sets sender, receiver body etc
This works fine. The email gets submitted.
Replacing the above code with :
$smtp = Net::SMTP->new("$mailserver",
Hello => "$localhostname",
Timeout => 60,
Port => "$port", //Port value is 465
Debug => 1);
$smtp->auth($username, $password);
...Remaining script which sets sender, receiver body etc
This fails. The debug logs look like this:
Net::SMTP>>> Net::SMTP(3.11)
Net::SMTP>>> Net::Cmd(3.11)
Net::SMTP>>> Exporter(5.73)
Net::SMTP>>> IO::Socket::INET(1.39)
Net::SMTP>>> IO::Socket(1.39)
Net::SMTP>>> IO::Handle(1.39)
Net::SMTP: Net::Cmd::getline(): unexpected EOF on command channel: at fescommon/mailsend-new.pl line 67.
Can't call method "auth" on an undefined value at fescommon/mailsend-new.pl line 74.
Note: Modules like Net::SMTP, Net::SMTP::SSL, IO::Socket::SSL and others are all updated to the latest version.
Expected Result is that request on "submissions" service listening on port 465 on SMTP server can be made using latest Net::SMTP module, without using Net::SMTP::SSL (because the document claims)
If you want to use smtps (i.e. TLS from start instead TLS after the STARTTLS command) you have to explicitly say so. Net::SMTP does not magically derive this requirement from the port number. From the documentation:
new ( [ HOST ] [, OPTIONS ] )
SSL - If the connection should be done from start with SSL, contrary to later upgrade with starttls. You can use SSL arguments as documented in IO::Socket::SSL, but it will usually use the right arguments already.
Thus, the proper code should be:
$smtp = Net::SMTP->new($mailserver,
SSL => 1, # <<<<<<<<<<<<<<<<<<<<<<<< THIS IS IMPORTANT
Hello => $localhostname,
Timeout => 60,
Port => $port, # Port value is 465
Debug => 1
);

PHPList not able to connect to smtp server

Please guys help me.
This is my config:
$mail->SMTPAuth = true;
define('PHPMAILERHOST', 'tonyfintech.info');
$phpmailer_smtpuser = 'info#tonyfintech.info';
$phpmailer_smtppassword = 'azerty123';
$phpmailer_smtpport = '587';
$phpmailer_smtpsecure = 'tls';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => false
)
);
define('TEST', 0);
define('PHPMAILER_SMTP_DEBUG', 1);
I still have this error:
2018-10-30 21:04:23 CLIENT -> SERVER: EHLO tonyfintech.info
2018-10-30 21:04:23 CLIENT -> SERVER: STARTTLS
SMTP Error: Could not connect to SMTP host.
2018-10-30 21:04:23 CLIENT -> SERVER: QUIT
This configuration works well in my other server but not this one.
By the way, When I send an email using PHPMailer "just for testing" , it works with no issue .
The issue come from PHPList
The fact that it works on one server but not another suggests it's an environmental problem, not your code. The most likely explanation is that your server's CA certificate bundle is outdated, which is covered extensively on here and in the PHPMailer troubleshooting guide.
You should not be disabling certificate verification, though at a guess I'd say that PHPList isn't using your PHPMailer instance, which is probably why it's failing, because the certificate verification disabling you've done only applies to PHPMailer, not PHPList.
Fix your certificates and it will work in both.

Error when an email is sent from Wildfly 10.1.0

I configured my Wildfly (in domain mode) to send e-mails using Mail Session and Remote Socket Bindings.
After fill with the SMTP server, port 587, username, password and etc, I receive an error when the Wildfly try to send the e-mail:
Client was not authenticated to send anonymous mail during MAIL FROM
My credentials to authenticate in the SMTP server are correct.
I already try to flag the Enable SSL? for true in the Web Console, but I can't even connect in the server when I enable SSL.
I thinking the problem is that I need to enable TLS and not SSL. In the old Jboss I can do this using property, like this:
<property name="mail.smtp.tls" value="true"></property>
<property name="mail.smtp.starttls.enable" value="true"></property>
But I can't see this possibility in Wildfly and I'm trying to not edit any XML.
So, how can I set the TLS for true in Wildfly?
Well, I find the right command to apply in the domain controller. The big problem here is that the Web Console doesn't show the Use TLS? option...
After enter in the domain server, with the Jboss Client, you can set the TLS for true:
/profile=full-ha/subsystem=mail/mail-session=MyMailSession/server=smtp:write-attribute(name=tls, value=true)
You can see the change with this command:
/profile=full-ha/subsystem=mail/mail-session=MyMailSession/server=smtp:read-resource()
{
"outcome" => "success",
"result" => {
"outbound-socket-binding-ref" => "mail-smtp",
"password" => "PASSWORD",
"ssl" => false,
"tls" => true,
"username" => "domain.com"
}
}

Mail Exception only on server

Stage
I have a web application which I deployed recently. Application needs to send emails for several reasons.
I am using yandex business email service for my domain, have many email accounts for my domain, and I can use those email addresses without any problem.
I have written some code to send email on my Laravel application, using Laravel's Mail::send. See it below at #2. And you can see my config/mail.php settings at #1 below.
I am testing my application on my windows computer, with WAMP server.
My production server is VPS server running Linux. PHP version 5.5.29.
Problem
Everything works perfectly on my local test environment;
I can send mails, and they are delivered to hotmail, gmail or my domain's emails without any problem.
On the server however, I receive an error when I try to send an email. See #3 for error.
On the same server, I am able to send emails using PHPMailer with same email accounts, email settings and credentials, and without any problem.
Question and thoughts
Everything works on my local environment as expected and that makes me think it is a problem with my server configurations, PHP version, configuration or extensions, but I do not have the knowledge to judge that.
What have I tried and did not worked
Commented these lines to send email from default mail address.
And also changed my default email address with another one, which is also working everywhere except on production server of this project;
//$transport = Mail::getSwiftMailer()->getTransport();
//$transport->setUsername($username);
//$transport->setPassword($password);
Disabled mail encryption. Set;
'encryption' => '',
Tried different driver;
'driver' => 'mail',
1) My config/mail.php
'driver' => 'smtp',
'host' => 'smtp.yandex.com',
'port' => 587,
'from' => ['address' => 'name#domain.com', 'name' => 'name'],
'encryption' => 'tls',
'username' => 'name#domain.com',
'password' => 'password',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
2) Code I use
Mail::send($message, $data, function ($message) use ($account, $to, $subject)
{
$acc = config("mail.accounts.$account");
$senderAddress = array_get($acc, 'address');
$username = array_get($acc, 'username', $senderAddress);
$password = array_get($acc, 'password', '');
$senderName = array_get($acc, 'name', $acc['address'], $senderAddress);
$replyToAddress = array_get($acc, 'replyTo.0', $senderAddress);
$replyToName = array_get($acc, 'replyTo.1', $senderName);
$message->from($senderAddress, $senderName)
->replyTo($replyToAddress, $replyToName)
->subject($subject)
->to($to);
$transport = Mail::getSwiftMailer()->getTransport();
$transport->setUsername($username);
$transport->setPassword($password);
});
Explanation for code above:
This code basically allows me to send emails to any email account,
and from many email accounts I have. And like I said, this works perfectly on my local test environment.
3) The Error
Swift_TransportException in AuthHandler.php line 181:
Failed to authenticate on SMTP server with username
"name#domain.com" using 2 possible authenticators
4) Working PHPMailer Script
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.yandex.com";
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = $sender; // SMTP account username
$mail->Password = $password; // SMTP account password
$mail->SetFrom($sender, 'Name');
$mail->AddReplyTo($sender, 'Name');
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->AddAddress($to, $to);
$mail->Send();
It's hard to say what the problem can be. Or why it works on your development environment. But a quick google search gave me the following settings for smpt.yandex.com:
mail server address — smtp.yandex.com;
connection security — SSL;
port — 465.
So, it shouldn't work on your dev environment. Why it does work is a mystery to me.
see: https://yandex.com/support/mail/mail-clients.xml

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.