error send email with phpmailer in server domain but succed in localhost - oop

i have detail error with this problem,
SMTP -> FROM SERVER:220-server.modulindo.com ESMTP Exim 4.77 #2 Wed, 11 Jul 2012 10:57:22 +0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SMTP -> FROM SERVER: 250-server.modulindo.com Hello mail.modulindo.com [202.67.9.42] 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP
SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data
SMTP -> FROM SERVER:250 Reset OK
please help me guys!?
i have a problem with phpmailer. i send email with phpmailer in localhost is succeed, but when i upload it in my server domain, there was an error happend. the error is..
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
this is my script..
....
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "wasis85#gmail.com";
$mail->Password = "password";
$mail->From = "wasis85#gmail.com";
$mail->FromName = "Wasis Lukito";
$mail->AddAddress($ema[$ari_no],"wasis");
$mail->AddCC("wasisl85#yahoo.com");
$mail->AddReplyTo("wasisl85#yahoo.com","Wasis Lukito");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Penolakan Data BPLPSE";
$mail->Body = "Alasan di tolak ";
$mail->AltBody = "This research is supported by Google.com";
...

i solved same problem with comment (or cancel) this line
// $mail->IsSMTP();
this because from some server i had same error: SMTP Error: Could not authenticate (also Password is incorrect...etc)

The script seems to be fine. I believe you have to check and make sure if your server supports SMTP or it has been properly configured for SMTP or not.

Related

PHP mail function not working in cpanel using G Suit

I want to submit my form on email but PHP mail function not working in my hostgator cloud server, i am using G Suit on this server. Please help
You can use PHPMailer instead of server mailing as send emails from php not work in most host providers so PHPMailer solve your problem as you can send email over SMTP from php
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "name#gmail.com";
$mail->Password = "super_secret_password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "name#gmail.com";
$mail->FromName = "Full Name";
$mail->addAddress("name#example.com", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent successfully";
}
?>
PHPMailer docs https://github.com/PHPMailer/PHPMailer/wiki/Tutorial

Using MailKit to send through Outlook.com

I'm trying to send an email through my Outlook.com email address using MailKit.
I've followed all the examples I've seen online and this is what I have:
public async Task SendEmailAsync(string email, string subject, string htmlmessage)
{
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Service Account", "me#outlook.com"));
message.To.Add(new MailboxAddress("First Last", email));
message.Subject = subject;
message.Body = new TextPart(TextFormat.Html)
{
Text = htmlMessage
};
using (var client = new SmtpClient())
{
//Have tried both false and true
client.Connect("smtp-mail.outlook.com", 587, false);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("me#outlook.com", "mypassword");
await client.SendAsync(message);
client.Disconnect(true);
}
return;
}
If I set the useSSL parameter to true on client.Connect(), I get this error:
An error occurred while attempting to establish an SSL or TLS connection
If I set the useSSL parameter to false, I get this error:
AuthenticationException: AuthenticationInvalidCredentials: 5.7.3 Authentication unsuccessful
What am I doing wrong?
Update
Added ProtocolLogger per the suggestion of #jstedfast and here was the result:
Connected to smtp://smtp-mail.outlook.com:587/?starttls=when-available
S: 220 BN6PR11CA0009.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sun, 10 Feb 2019 03:26:30 +0000
C: EHLO [192.168.1.12]
S: 250-BN6PR11CA0009.outlook.office365.com Hello [73.175.143.94]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-STARTTLS
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 SMTP server ready
C: EHLO [192.168.1.12]
S: 250-BN6PR11CA0009.outlook.office365.com Hello [73.175.143.94]
S: 250-SIZE 157286400
S: 250-PIPELINING
S: 250-DSN
S: 250-ENHANCEDSTATUSCODES
S: 250-AUTH LOGIN XOAUTH2
S: 250-8BITMIME
S: 250-BINARYMIME
S: 250-CHUNKING
S: 250 SMTPUTF8
C: AUTH LOGIN
S: 334 ************
C: ****************
S: 334 ************
C: ****************
S: 535 5.7.3 Authentication unsuccessful [BN6PR11CA0009.namprd11.prod.outlook.com]
BTW, I commented out some stuff with *. I wasn't sure what that was and if it was sensitive or not.
It appears as though the code itself works. However, be aware that if you've set your account to require 2FA, you will get the error message above that indicates that your credentials are invalid. Be sure to disable 2FA!
If the problem you're facing is because of 2FA (2-factor Authentication) you should go to your Microsoft settings, in advanced settings you could request an "app password" once you receive it, you should use it instead of your email's password, worked for me.
try in this way:
client.Connect("smtp-mail.outlook.com", 587);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(From, Password);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
You can also try client.ConnectType = SmtpConnectType.ConnectSSLAuto;
For MailKit
client.Connect("smtp-mail.outlook.com", 587, SecureSocketOptions.StartTls);
client.Authenticate("me#outlook.com", "mypassword");
I have been struggling with this issue myself for a new exchange online account (without 2FA). The account was for a customer and so I did not configure the account in my email client. After many attempts I added the account to my Outlook client and sent a test email. After that the issue was solved. Hope this will help others to solve the problem.
The AuthenticationException error means that the server is rejecting your user name and/or password.
Perhaps the username should be me instead of me#outlook.com?
Try getting a protocol log and seeing what type of authentication mechanism is being used.
https://github.com/jstedfast/MailKit/blob/master/FAQ.md#ProtocolLog

postfix check the From address field matches the authenticated username or other valid aliases in LDAP

We have an internet facing MX server whereby all users authenticate their outgoing connection to submit emails via port 587. This MX server routes incoming mail for our domain to an internal postfix smtp server which then delivers mail to local imap servers.
The internal postfix smtp server users LDAP alias_maps = ldap:/etc/postfix/ldap-aliases.cf, to lookup which imap server a users mailbox resides on.
There is a postfix option...
reject_sender_login_mismatch
that can be mapped...
smtpd_sender_login_maps = ldap:/etc/postfix/smtpd_sender_login.cf
However - I get the following error
Jul 4 11:23:26 smtp-1.domain1.com postfix/smtpd[31530]: warning: restriction `reject_authenticated_sender_login_mismatch' ignored: no SASL support
No users authenticate to the internal postfix smtp server - all it does is route emails from the MX server. I believe the reason I see the warning "no SASL support" is because postfix doesn't handle the authentication as it's taken care of by the MX server.
postconf -n
alias_database = hash:/etc/aliases
alias_maps = ldap:/etc/postfix/ldap-aliases.cf, hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
message_size_limit = 51200000
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mx3.$mydomain, mx1.$mydomain, mx2.$mydomain
mydomain = domain1.com
myhostname = smtp-1.domain1.com
mynetworks = xxx.xxx.192.0/21, xxx.62.52.0/22, 10.0.0.0/8, xxx.16.0.0/12, xxx.168.0.0/16
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_sender_login_maps = ldap:/etc/postfix/ldap-senders.cf
smtpd_sender_restrictions = reject_authenticated_sender_login_mismatch
unknown_local_recipient_reject_code = 550
However, with a different config "smtpd_sender_restrictions = reject_unverified_sender"
If the "envelope From field" contains an invalid forged address the following is logged - which is great to stop unknown email address being forged - but doesn't help if it's forged with a known email address.
NOQUEUE: reject: RCPT from mx.domain1.com[xxx.xxx.192.130]: 450 4.1.7 : Sender address rejected: unverified address: unknown user: "hejem"; from= to= proto=ESMTP helo=
-bash-4.1$ postconf -n
alias_database = hash:/etc/aliases
alias_maps = ldap:/etc/postfix/ldap-aliases.cf, hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
message_size_limit = 51200000
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mx3.$mydomain, mx1.$mydomain, mx2.$mydomain
mydomain = domain1.com
myhostname = smtp-1.domain1.com
mynetworks = xxx.xxx.xxx.0/21, xxx.xxx.xxx.0/22, xxx.0.0.0/xxx, xxx.xxx.0.0/12, xxx.xxx.0.0/16
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_sender_restrictions = reject_unverified_sender"
What I want to achieve is my local internal postfix to check the "envelope From field" to ensure it's not been spoofed by knowing the sending user's username and looking up it's assigned "From" aliases in LDAP if it doesn't match i.e. they're spoofing then reject the mail.
Any advice how to implement this check in postfix?
Thanks
Firstly, it is not considered a good practice to activate reject_unverified_sender in postfix services. If you want to prevent mails being sent from non-existing addresses in your domain, you should prefer reject_unlisted_sender.
You can not be sure of spoofing of existing mail addresses without activating authentication (SASL) mechanism on postfix service. Thus, to prevent spoofing of existing addresses:
Make sure that smtpd_sender_login_maps is properly configured.
Activate SASL authentication on postfix
Configure reject_authenticated_sender_login_mismatch or reject_sender_login_mismatch depending on your preference.
Further Reading (from postfix SASL documentation)
Envelope sender address authorization
By default an SMTP client may specify any envelope sender address in the MAIL FROM command. That is because the Postfix SMTP server only knows the remote SMTP client hostname and IP address, but not the user who controls the remote SMTP client.
This changes the moment an SMTP client uses SASL authentication. Now, the Postfix SMTP server knows who the sender is. Given a table of envelope sender addresses and SASL login names, the Postfix SMTP server can decide if the SASL authenticated client is allowed to use a particular envelope sender address:
/etc/postfix/main.cf:
smtpd_sender_login_maps = hash:/etc/postfix/controlled_envelope_senders
smtpd_recipient_restrictions =
...
reject_sender_login_mismatch
permit_sasl_authenticated

sending mail through phpmailer error

helo guys i have been trying to send a mail through php script for the last 8 days first i was using the php mail() on the server it returned false after alot of searching then company told me they have disabled this feature and told me to use my gmail account for sending mail then i googled it and found phpmailer swiftmailer and other software finally i decided to use phpmailer and included 3-4 files on my root folder as described here(http://phpmailer.worxware.com/index.php?pg=install#) i used this code
<?php
require("class.phpmailer.php");
include('class.smtp.php');
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->SMTPSecure = 'ssl';
$mail->Username = "myid#gmail.com"; // SMTP account username
$mail->Password = "xxxxxxx"; // SMTP account password
$mail->From = "myid#gmail.com";
$mail->AddAddress("hostimf#gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>`
it is returning errors that are listed in my firefox browser like this
2015-07-24 20:12:02 CLIENT -> SERVER: EHLO localhost
2015-07-24 20:12:02 CLIENT -> SERVER: AUTH LOGIN
2015-07-24 20:12:03 CLIENT -> SERVER: c2lkZGhhbnRiYWh1Z3VuYUBnbWFpbC5jb20=
2015-07-24 20:12:03 CLIENT -> SERVER: Y2hpbXB1OTQ=
2015-07-24 20:12:04 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 2sm16058566pdp.68 - gsmtp
2015-07-24 20:12:04 SMTP Error: Could not authenticate.
2015-07-24 20:12:04 CLIENT -> SERVER: QUIT
2015-07-24 20:12:04 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message was not sent.Mailer error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting`
this i tried on my wamp server
pls help me i m going mad trying to solve this problem pls help..... thanks

When smtp mail returns a "password not accepted from server"

You get this error from phpmailer.
"Password not accepted from server: 535 Incorrect authentication data"
What causes this?
You must make sure that the Username given for the log-on is the same as the SetFrom email address.
This will return an error:
$mail->Username = "myemailaddress#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('mysetfromaddress#gmail.com', 'Pagelinks');
This should not.
$mail->Username = "mysetfromaddress#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('mysetfromaddress#gmail.com', 'Pagelinks');
When the Username and SetFrom do not match the authentication fails (according to an article found on Google).