SMTP Email Send Issue by using PHPMailer - visual-studio

I am New here .I am facing recently Email Send issue from my Windows server. 50% cases mail are unable to send User.
Below Error message are showing
*******Password not accepted from server: 421 4.7.66 TLS 1.0 and 1.1 are not supported. Please upgrade/update your client to support TLS 1.2. Visit https://aka.ms/smtp_auth_tls. [SI2P153CA0009.APCP153.PROD.OUTLOOK.COM]*******
This is my Mail Server Configuration code :
<?php
//require_once('class.phpmailer.php');
//date_default_timezone_set('PRC'); //Set China time zone
date_default_timezone_set('Asia/Dhaka');
$mail = new PHPMailer(); //Instantiate
$mail->SetLanguage("en", 'language.php');
$mail->SMTPDebug = 4;
$mail->SetLanguage("en");
$mail->IsSMTP(); // Enable SMTP
$mail->SMTPAuth = true; //Enable SMTP authentications
$mail->SMTPSecure = 'tls';
$mail->Host = "Smtp.office365.com"; //SMTP server Take 163 mailbox as an example
$mail->Port = 587; //Mail sending port
$mail->Username = "UserName"; //your mailbox
$mail->Password = "Password"; //Your password
?>
I have install Visual studio 2022 for upgrading .NET framework .
Can you please Tell me how can I solved issue ?

The first thing you should always do when presented with an error message is to read it:
TLS 1.0 and 1.1 are not supported. Please upgrade/update your client to support TLS 1.2. Visit https://aka.ms/smtp_auth_tls
This suggests that your server, or at least the PHP version you are running on it, is badly outdated. On top of that, I can see that you are using a very old and unsupported version of PHPMailer, so upgrade.

Finally solved it .I updated my code and Using Latest PHPMailler version .getting 100% mail right now .Below code works for me ..
<?php
require 'includes/PHPMailer.php';
require 'includes/SMTP.php';
require 'includes/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(); //Instantiate
$mail->isSMTP(); // Enable SMTP
$mail->Host = "Smtp.office365.com"; //SMTP
$mail->SMTPAuth = "true"; //Enable SMTP authentications
$mail->SMTPSecure = "tls";
$mail->Port = "587"; //Mail sending port
$mail->Username = "Username"; //your mailbox
$mail->Password = "Password"; //Your
?>

Related

Sending Email Using SMTP Bluehost Server

I use ASP.NET WEB API and I want to send an email from my application from an email created by https://www.bluehost.com/
Here is the configuration in the web.config file:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="example#domain.com">
<network host="mail.domain.com"
port="465"
userName="example#domain.com"
password="*****"
enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
Here is my code:
SmtpClient smtpClient = new SmtpClient();
smtpClient.Timeout = 120000;
MailMessage mail = new MailMessage("fromMailAddress#domain.com", "toMailAddress#gmail.com");
mail.Body = "Here is the body of my email";
mail.IsBodyHtml = true;
smtpClient.Send(mail);
I am receiving the following error:
Network Error (tcp_error)
A communication error occurred: "Operation timed out"
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.
Note that I have tried configuring SMTP directly in the above code, but still it didn't work.
I had tested from host smtp.gmail.com and it worked fine, so I guess the issue is from the new host.
Any help is much appreciated.
Please try this below code segment.
SmtpClient smtpClient = new SmtpClient();
smtpClient.Port = 465; // can check port for ssl - 587 and non ssl - 25
smtpClient.Host = "mail.domain.com";
smtpClient.EnableSsl = true;
smtpClient.Timeout = 10000;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential("example#domain.com","password");
MailMessage mail = new MailMessage("donotreply#domain.com", "sendtomyemail#domain.com", "test", "test");
mail.BodyEncoding = UTF8Encoding.UTF8;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
smtpClient.Send(mail);
For SMTP, I used port 26 and mail.company.com. My host server is bluehost.

How to send email in xampp localhost using PHPmailer?

I have attached two different PDF files (mnlocalXampp and rnlocalXampp) that is phpinfo of two different pcs. I have checked both information and seem that both have same information and using same version of PHP but I'm receiving email in mnlocalXampp but not in rnlocalXampp. I also activated openssl in both but i am still not receiving email in rnlocalxampp. Can anyone please look at both the files and let me know what difference in that files and how to configure.
<?php
require 'email_class/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
$mail->Host = 'cp-in-10.webhostbox.net'; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = '465'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = 'mn#infotech.com'; //Sets SMTP username
$mail->Password = 'xxxxxxx'; //Sets SMTP password
$mail->SMTPSecure = 'ssl'; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = 'mn#infotech.com'; //Sets the From email address for the message
$mail->FromName = "mn"; //Sets the From name of the message
$mail->AddAddress("m#infotech.com"); //Adds a "To" address
$mail->AddCC("m#infotech.com"); //Adds a "Cc" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$mail->IsHTML(true); //Sets message type to HTML
$mail->Subject = 'Project CMS'; //Sets the Subject of the message
$mail->Body = $message; //An HTML or plain text message body
$mail->AddStringAttachment($doc, 'doc.pdf', 'base64', 'application/pdf');
$mail->Send(); ?>
The above sample code is email configuration of mnlocaXampp. For the rnlocalXampp I'm using different Port(Port number: 25), Hosting, SSL enabled.
mnlocalXampp
rnlocalXampp
Thanks in advance
Difficult to know where to start.
You've based your code on an obsolete example and you're using an old version of PHPMailer, so get the latest, and base your code on the examples provided.
You're not defining $doc before you use it.
addStringAttachment is the wrong method to use if you're trying to send a local file; use addAttachment instead.
The definition of $headers is pointless.
There's no point in CC'ing an address you're already sending to.
You have no error checking anywhere.
Resolving some of the above items may help to fix your problem.

Codeigniter send mail working in localhost but not in server

What I am trying
I am building a codeigniter application and need to send mail. My mail configuration works perfectly when I try to send mail from localhost. But its not working when host it on server.
Mail Config
var $useragent = "CodeIgniter";
var $mailpath = "/usr/sbin/sendmail"; // Sendmail path
var $protocol = "smtp"; // mail/sendmail/smtp
var $smtp_host = "send.one.com"; // SMTP Server. Example: mail.earthlink.net
var $smtp_user = "no-reply#domain.com"; // SMTP Username
var $smtp_pass = "pass"; // SMTP Password
var $smtp_port = "25"; // SMTP Port
var $smtp_timeout = 60; // SMTP Timeout in seconds
var $smtp_crypto = ""; // SMTP Encryption. Can be null, tls or ssl.
var $wordwrap = TRUE; // TRUE/FALSE Turns word-wrap on/off
var $wrapchars = "76"; // Number of characters to wrap at.
var $mailtype = "html"; // text/html Defines email formatting
var $charset = "utf-8"; // Default char set: iso-8859-1 or us-ascii
var $multipart = "mixed"; // "mixed" (in the body) or "related" (separate)
var $alt_message = ''; // Alternative message for HTML emails
var $validate = FALSE; // TRUE/FALSE. Enables email validation
var $priority = "1"; // Default priority (1 - 5)
var $newline = "\r\n"; // Default newline. "\r\n" or "\n" (Use "\r\n" to comply with RFC 822)
var $crlf = "\r\n";
I am getting the following error while sending from server
A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to send.one.com:25 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1689
The application is hosted at one.com
I had the same problem. After trying several times and failing to find a solution, I changed my protocol to mail. If you are changing the email protocol you may recieve the following error:
A PHP Error was encountered
Severity: Warning
Message: mail(): Policy restriction in effect. The fifth parameter is disabled on this system
Filename: libraries/Email.php
Line Number: 1537
Just change the code at /system/libraries/email.php in function _send_with_mail()
from
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])))
to
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str))
because of: “// most documentation of sendmail using the “-f” flag lacks a space after it, however
// we’ve encountered servers that seem to require it to be in place.”
Hope someone can give a solution for sending mail using smtp.
I'm also looking for the solution and most of the time every thing going great on localhost but on server just hell every thing. But after many try one thing I understand as per different servers like - Godaddy, Plesk, Hostinger etc...
It's a game of protocole and port number like -
var $protocol = "smtp";
var $protocol = "tls";
var $protocol = "imps";
var $protocol = "mail";
var $protocol = "sendmail";
Same for port -
var $smtp_port = "25"; //It works most of time on localhost
var $smtp_port = "465"; //For gmail
var $smtp_port = "587"; // Sometime work for gmail and for others
var $smtp_port = "995"; // On few cases
Also there is some cases of smtp user
var $smtp_user = "ssl://smtp.gmail.com";
var $smtp_user = "ssl://smtp.googlemail.com";
var $smtp_user = "tls://smtp.yourmail.com";
var $smtp_user = "imps://smtp.yourmail.com";
var $smtp_user = "smtp.gmail.com";
var $smtp_user = "smtp.googlemail.com";
But most of servers not allow ssl:// or all other prefix they direct want the email address.
Yes it's to confuging but it's ture to configer email on server it's like milestone for first time user on server but after that you know how things going on server and you will easiely find your soluton or not.
But good luck.

config email yahoo, AOL for codeigniter from the local server

I used the following code for yahoo and it did not work, can you help where I am doing wrong. The same code when I used for the gmail with host as smtp.gmail.com it worked well. I am trying to send an email from the local server using yahoo, AOL, windows hotmail . The following is a file created in application/config folder with the name email.php
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.mail.yahoo.com";
$config['smtp_user'] = "myusername#yahoo.com";
$config['smtp_pass'] = "**************";
$config['smtp_port'] = "465";
$config['charset']="utf-8";
$config['newline']="\r";
$config['crlf'] = "\r";
The working code for gmail
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_user'] = "username#gmail.com";
$config['smtp_pass'] = "*****";
$config['smtp_port'] = '465';
$config['charset']='utf-8';
$config['newline']="\r\n";
$config['crlf'] = "\r\n";
Yahoo uses port 995 as the outgoing mail port
http://www.emailaddressmanager.com/tips/mail-settings.html

Exporting exchange mails to Excel using lotusscript agent or Java agent or Javascript language

i want to export mails on exchnage server (subject line and body content) to Excel using lotusscript agent or Java agent or Javascript language. How can I acheive this? Any idea, suggestion or sample code is appreciable.
After doing reasearch found code to download mails from POP3 server. I used below code but got stuck at var oServer = new ActiveXObject("EAGetMailObj.MailServer"); with error - "Automation server can't create object". Then I put the host url in trusted sites and enabled active x control settings of IE, but then also getting the same error. Any idea, why?
The following code demonstrates how to receive email from a POP3 mail account. This sample downloads emails from POP3 server and deletes the email after the email is retrieved.
Code:
MailServerPop3 = 0;
MailServerImap4 = 1;
try
{
var oServer = new ActiveXObject("EAGetMailObj.MailServer");
// please change the server, user, password to yours
oServer.Server = "pop3.adminsystem.com"
oServer.Protocol = MailServerPop3;
oServer.User = "testx";
oServer.Password = "testpassword";
// If your server requires SSL connection,
// Please add the following codes.
oServer.SSLConnection = true;
oServer.Port = 995;
var oClient = new ActiveXObject("EAGetMailObj.MailClient");
oClient.LicenseCode = "TryIt";
// Connect POP3 server.
oClient.Connect(oServer);
var infos = new VBArray(oClient.GetMailInfos()).toArray();
for (var i = 0; i < infos.length; i++) {
var info = infos[i];
// Receive email from POP3 server
var oMail = oClient.GetMail(info);
// Save email to local disk
oMail.SaveAs("d:\\" + i + "_test.eml", true);
// Mark email as deleted on server.
oClient.Delete(info);
}
// Quit and pure emails marked as deleted from POP3 server.
oClient.Quit
}
catch( err )
{
WScript.Echo( err.description );
}
You can use Java and the Exchange Web Services API Java implementation at http://archive.msdn.microsoft.com/ewsjavaapi

Resources