Sending Email Using SMTP Bluehost Server - asp.net-web-api

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.

Related

SMTP Email Send Issue by using PHPMailer

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
?>

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.

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

How to setup selfhosted https WCF service with embedded certificates on client and server?

Im creating a simple WCF service for receiving crash reports.
The service will run self-hosted as a console program and must run without any installation of certificates.
Security-wise i need to ensure that the data send by the client is only send to our server and that the data is not intercepted. From the server point of view i would also like to ensure that the connecting client is using a specific certificate (embedded in the client assembly) to discourage abuse of the service.
I have created a single self-signed certificate and plan to embed the .cer (containing the public part of the certificate) in the client assembly and embed the PFX containing the certificate with the private key into the service host program assembly. (I was led to believe by this that i could use a single certificate).
My problem is that no matter how is setup this up i get the following error:
"An error occurred while making the HTTP request to https://localhost:8080/errorservice. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server."
There shouldnt be a mismatch between the bindings, as they are created using the same code:
public static BasicHttpBinding CreateStreamingBinding() {
BasicHttpBinding streamBinding = new BasicHttpBinding();
streamBinding.TransferMode = TransferMode.StreamedRequest;
streamBinding.MaxReceivedMessageSize = long.MaxValue;
streamBinding.Security = new BasicHttpSecurity
{
Transport = new HttpTransportSecurity
{
ClientCredentialType = HttpClientCredentialType.None,
ProxyCredentialType =HttpProxyCredentialType.None
},
Mode = BasicHttpSecurityMode.Transport,
};
streamBinding.MaxBufferSize = int.MaxValue;
streamBinding.MessageEncoding = WSMessageEncoding.Mtom;
streamBinding.SendTimeout = new TimeSpan( 1, 0, 0, 0, 0 );
streamBinding.ReceiveTimeout = new TimeSpan( 1, 0, 0, 0, 0 );
return streamBinding;
}
On the client the code to create service is setup like this (the certificate location is just for testing):
protected ErrorReportingServiceClient CreateClient() {
X509Certificate2 cert = new X509Certificate2( #"C:\certs\reporting.cer" );
EndpointAddress endpointAddress = new EndpointAddress( new Uri( ReportingServiceUri ));
ErrorReportingServiceClient client = new ErrorReportingServiceClient( CreateStreamingBinding(), endpointAddress );
client.ClientCredentials.ServiceCertificate.DefaultCertificate = cert;
client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
client.ClientCredentials.ClientCertificate.Certificate = cert;
return client;
}
On the service side the setup is as follows:
X509Certificate2 cert = new X509Certificate2( #"C:\certs\reporting.pfx", <password>);
BasicHttpBinding basicHttpBinding = CreateStreamingBinding();
host.Credentials.ClientCertificate.Certificate = cert;
host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
host.Credentials.ServiceCertificate.Certificate = cert;
host.AddServiceEndpoint( contractType, basicHttpBinding, baseAddress );
Any help on how to setup this correctly would be greatly appreciated.
The question was answered on the MSDN forums:
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/14f44296-5e3d-4df5-8cc4-a185415852b7

Resources