I have a VPS server which is running postfix + dovecot as mail server.
I have already created two accounts which work well. Both can send and receive email via STARTTLS and SSL.
But when I added a third account today, it can only receive email but failed to connect SMTP server. So it is not a issue of wrong password. The SMTP settings are same as the other two accounts. The settings of client should be correct.
The postfix log says:
Aug 28 12:55:32 server postfix/smtpd[1645]: warning: SASL authentication failure: Password verification failed
Aug 28 12:55:32 server postfix/smtpd[1645]: warning: unknown[203.97.197.232]: SASL PLAIN authentication failed: authentication failure
Aug 28 12:55:35 server postfix/smtpd[1645]: warning: unknown[203.97.197.232]: SASL LOGIN authentication failed: authentication failure
The sasl and tls settings in main.cf is:
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = cyrus
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_tls_auth_only = no
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt
smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
Can anyone help me out?
Thank you very much.
Related
When using hard-coded username / email / password I have no problem getting a message sent with phpmailer. But when I use $_ENV to hide the credentials I get the smtp error as shown here:
2020-09-08 15:50:51 SERVER -> CLIENT: 220 dd45234.kasserver.com ESMTP
2020-09-08 15:50:51 CLIENT -> SERVER: EHLO browsegenres-f3.loc
2020-09-08 15:50:51 SERVER -> CLIENT: 250-dd45234.kasserver.com250-PIPELINING250-SIZE 102400000250-VRFY250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2020-09-08 15:50:51 CLIENT -> SERVER: STARTTLS
2020-09-08 15:50:51 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2020-09-08 15:50:51 CLIENT -> SERVER: EHLO xxxxxxxxxxxxxxxxxxxx.loc
2020-09-08 15:50:51 SERVER -> CLIENT: 250-xxxxxxxx.[SERVER].com250-PIPELINING250-SIZE 102400000250-VRFY250-ETRN250-AUTH PLAIN LOGIN250-AUTH=PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2020-09-08 15:50:51 CLIENT -> SERVER: AUTH LOGIN
2020-09-08 15:50:51 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-09-08 15:50:51 CLIENT -> SERVER: [credentials hidden]
2020-09-08 15:50:53 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: VXNlcm5hbWU6
2020-09-08 15:50:53 SMTP ERROR: Username command failed: 535 5.7.8 Error: authentication failed: VXNlcm5hbWU6
SMTP Error: Could not authenticate.
2020-09-08 15:50:53 CLIENT -> SERVER: QUIT
2020-09-08 15:50:53 SERVER -> CLIENT: 221 2.0.0 Bye
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.
I don't wan to hardcode the credentials. Any idea how to get rid of this error?
Here's the code:
// initiate phpMailer
$mail = new PHPMailer(true);
// see config file
$mailSenderName = $_ENV['MAILER_CONTACT_USERNAME'];
$masterPassword = $_ENV['MAILER_CONTACT_PASSWORD'];
$masterEmail = $_ENV['MAILER_CONTACT_EMAIL'];
$recipient = $_ENV['MAILER_CONTACT_RECIPIENT'];
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'xxxxxxx.[SERVER].com';
$mail->SMTPAuth = true;
$mail->Username = $masterEmail;
$mail->Password = $masterPassword;
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 25;
//Recipients
$mail->setFrom('aaa#bbbbbbbbbbb.com', 'aabbcc');
$mail->addAddress('mmmmmmmmm#bbbbbbbbbbb.com');
// Content
$mail->isHTML(true);
$mail->Subject = 'Message Received (Contact Page)';
$emailbody =
'There is a new message from: <br>' .
'==================================== <br>' .
$senderName . '<br>' .
$senderEmail . '<br' .
'====================================' .
$message . '<br>' .
'====================================';
$mail->Body = $emailbody;
$mail->send();
// success, show thank you
$f3->reroute('/contact/thankyou'); //todo
} catch (\Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Thanks!
Debug one thing at a time. There's no point in looking at error in your email when you know you know you have a problem before it ever gets that far. PHPMailer uses whatever you give it, so you need to be sure you're giving it the right thing.
You could reduce the code to debug in this case by cutting it back to:
var_dump($_ENV);
Once you know that you're setting the contents of $_ENV correctly (whether from real env vars, from a dotenv script, your php.ini config, etc), you can then start using the values in your email code.
After installing dotenv (vlucas) I simply didn't include it correctly in my ContactController. So that's why var_dump($_ENV) always resulted in NULL. I compared my settings with the other route, NewsletterController. The difference is that in this route I query the database and in the models constructor (where the db connection is set) I 'use' the dotenv class correctly, and that's why the $_ENV is filled with data. I simply didn't see it.
So, in ContactController I set:
use \Dotenv;
and after initialising phpmailer I added:
$mail = new PHPMailer(true);
$dotenv = Dotenv\Dotenv::createImmutable($_SERVER['DOCUMENT_ROOT']);
$dotenv->load();
Difference to Models class (database connection):
namespace Models;
use \Dotenv;
abstract class Model
{
protected $db;
public function __construct()
{
$dotenv = Dotenv\Dotenv::createImmutable($_SERVER['DOCUMENT_ROOT']);
$dotenv->load();
$this->db = new \DB\SQL(
'mysql:host='. $_ENV['DB_HOST'] .';port='.$_ENV['DB_PORT'].';dbname='.$_ENV['DB_NAME'],
$_ENV['DB_USERNAME'],
$_ENV['DB_PASSWORD']
);
}
}
Hello to the community.
I have come across a strange problem with PHPMailer.
I am trying to connect via SMTP to a host without encryption (port 25) and although I am able to connect to the said host via Outlook, the PHPMailer connection attempt fails with the message (10060):
Connection: opening to webmail.ypa.gr:25, timeout=300, options=array()<br>
2020-07-21 05:34:34 Connection failed. Error #2: stream_socket_client(): unable to connect to webmail.ypa.gr:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) [...]<br>
2020-07-21 05:34:34 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060)<br>
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
The parameters (host/port given by the server admins) set to PHPMailer ($EMAIL_CREDENTIALS) are dumped below.
array(9) {
["SMTP_HOST"]=>
string(14) "webmail.ypa.gr"
["SMTP_PORT"]=>
int(25)
["SMTP_AUTH"]=>
bool(true)
["SMTP_SECURE"]=>
bool(false)
["SMTP_AUTOTLS"]=>
bool(false)
["USERNAME"]=>
string(12) "..."
["PWD"]=>
string(6) "..."
["SENDER"]=>
string(12) "..."
["RECEIVER"]=>
string(12) "..."
}
This is the code snippet:
$mail = new PHPMailer(true);
var_dump($EMAIL_CREDENTIALS);
try
{
$mail->isSMTP();
$mail->SMTPDebug = 4;
$mail->Host = $EMAIL_CREDENTIALS["SMTP_HOST"];
$mail->Port = $EMAIL_CREDENTIALS["SMTP_PORT"];
$mail->SMTPAuth = $EMAIL_CREDENTIALS["SMTP_AUTH"];
$mail->SMTPSecure = $EMAIL_CREDENTIALS["SMTP_SECURE"];
$mail->SMTPAutoTLS = $EMAIL_CREDENTIALS["SMTP_AUTOTLS"];
$mail->Username = $EMAIL_CREDENTIALS["USERNAME"];
$mail->Password = $EMAIL_CREDENTIALS["PWD"];
$mail->setFrom($EMAIL_CREDENTIALS["SENDER"], "...");
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHTML($body);
$mail->send();
}
I have seen many answers to such problems but have not been able to fix it. Among others, I have explicitly disabled TLS.
Is there something else I can check?
Thank you.
Having a problem setting up authentication with smtp on my mail server using postfix. I have set up a test user inside of sasl_passwd file with info test:testpass. The same result is obtain when running AUTH LOGIN also.
220 rossiscloud.co.uk ESMTP Postfix
ehlo rossiscloud.co.uk
250-rossiscloud.co.uk
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH DIGEST-MD5 CRAM-MD5 NTLM PLAIN LOGIN
250-AUTH=DIGEST-MD5 CRAM-MD5 NTLM PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
AUTH PLAIN dGVzdAB0ZXN0AHRlc3RwYXNz
535 5.7.8 Error: authentication failed: authentication failure
Logs:
Feb 3 22:45:31 rossiscloud postfix/smtpd[8189]: warning: SASL authentication failure: Password verification failed
Feb 3 22:45:31 rossiscloud postfix/smtpd[8189]: warning: rossiscloud.co.uk[192.168.0.200]: SASL PLAIN authentication failed: authentication failure
Feb 3 22:45:36 rossiscloud postfix/smtpd[8189]: disconnect from rossiscloud.co.uk[192.168.0.200]
main.cf
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_sasl_auth_enable = yes
smtpd_tls_cert_file=/etc/letsencrypt/live/rossiscloud.co.uk/cert.pem
smtpd_tls_key_file=/etc/letsencrypt/live/rossiscloud.co.uk/privkey.pem
smtpd_use_tls=yes
smtpd_sasl_security_options = noanonymous
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
check_relay_domains
i tried to configure SMTP in my Gitlab-Instance (following this guideline). but dont get it working.
gitlab.rb
gitlab_rails['gitlab_email_from'] = "admin#example.com"
gitlab_rails['gitlab_support_email'] = "admin#example.com"
#nginx['redirect_http_to_https'] = false
#nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.crt"
#nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key"
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = 'smtp.exmail.qq.com'
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = 'admin#example.com'
gitlab_rails['smtp_password'] = 'has been removed'
gitlab_rails['smtp_domain'] = 'smtp.qq.com'
gitlab_rails['smtp_authentication'] = :plain
gitlab_rails['smtp_enable_starttls_auto'] = true
production.log
Sent mail to i#example.com (8017.5ms)
mail.log
May 9 09:02:14 nday postfix/smtp[27203]: B16EF12019C: to=<i#example.com>, relay=none, delay=1049, delays=1017/0.04/32/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=mxbiz2.qq.com type=AAAA: Host not found, try again)s
May 9 09:02:14 nday postfix/smtp[27202]: 40274120CA7: to=<i#example.com>, relay=none, delay=988, delays=955/0.04/32/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=mxbiz2.qq.com type=AAAA: Host not found, try again)
BTW:I have changed the DNS and refresh. mail.log haven't logged my operation. It's old log.
Is your account new on Digital Ocean?
If yes, you need to ask them to unlock sendmail functionality.
This unlock is by account, not by droplet.
You will can use sendmail in all others droplets created by you after this unlock.
I am currently trying to configure my first Postfix - Dovecot - PostgreSQL installation.
When I connect from Thunderbird, I can receive and send mail on my 3 domains with virtual and real mail accounts. Emails are instantaneously sent.
It works too when I use mail (mailutils). But emails need like 1 minute to be sent.
telnet 25 from the server and outside the server send mail correctly too. Emails are instantaneously sent.
However, when I try to send mail from my Gmail or Yahoo mail accounts to this domain, I receive this kind of error :
Gmail
Technical details of temporary failure:
The recipient server did not accept our requests to connect. Learn more at http://support.google.com/mail/bin/answer.py?answer=7720
[(10) mail.domain-1.com. [MY_IP]:25: Connection timed out]
And I don't get any message in /var/log when sending a mail from external domains
Software versions :
LinuxMint : 16 Petra (Debian Wheezy)
Postfix : 2.10.2
Dovecot : 2.1.7
PostgreSQL : 9.1.13
Here is my main.cf :
debug_peer_list = domain-1.com
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
append_dot_mydomain = no
readme_directory = no
transport_maps = pgsql:/etc/postfix/sql/transport.cf
virtual_uid_maps = pgsql:/etc/postfix/sql/uids.cf
virtual_gid_maps = pgsql:/etc/postfix/sql/gids.cf
virtual_alias_maps = pgsql:/etc/postfix/sql/virtual.cf
virtual_mailbox_maps = pgsql:/etc/postfix/sql/mailboxes.cf
virtual_mailbox_base = /var/spool/virtual_mailboxes/
virtual_mailbox_limit = 51200000
mydestination = domain-1.fr domain-2.com domain-3.org localhost.$mydomain localhost
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
queue_directory = /var/spool/postfix
Here is my master.cf :
smtp inet n - y - - smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_sasl_type=dovecot
-o smtpd_sasl_path=private/auth
There is currently no security like SSL or anti-spam. I just put an SHA512-CRYPT password.
As for my DNS configuration (it must come from here, ... but I don't see anything) :
domain-1.com. 10800 IN MX 10 mail.domain-1.com.
mail.domain-1.com. 10800 IN CNAME www.domain-1.com.
www.domain-1.com. 300 IN A SERVER_IP
I had just put a firewall only allowing mails from me.
Allowing anywhere on port 25 and 143 just made it...
...