In Email code, I get following error.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Is this indicating that we require SSL certificate ?
This error code means that you need to provide a valid credentials in order to use this smtp server:
var client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("youraccount#gmail.com", "secret");
Related
Trying to send email from asp.net application.
Emailing to server address: Smtp.office365.com
Port - 587
Connection Security - STARTTLS
I have SMTP user name and SMTP password.
Fails to send email.
The code uses the SmtpClient, as follows:
String userName = "name#example.com";
String password = "Password";
MailAddress RecipientEmail = new MailAddress(EmailTo);
MailAddress SenderEmail = new MailAddress(cEmailFrom);
MailMessage msg = new MailMessage(SenderEmail, RecipientEmail);
msg.Subject = "Test";
msg.Body = "This is a test";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.office365.com:587");
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.EnableSsl = true;
client.Send(msg);
The error message: Failure sending email. No other information.
But if I specify the port:
client.port = 587
instead of adding it to the host name, I get a very long error:
Transaction failed. The server response was: 5.2.0
STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:BC110000, 17.43559:0000000094000000000000000100000000000000, 20.52176:140FBF85130010100A00D231, 20.50032:140FBF85831710100A00E231, 0.35180:86260000, 255.23226:0A00C931, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A000000, 16.55847:DC000000, 17.43559:0000000088010000000000001E00000000000000, 20.52176:140FBF85130010109F260000, 20.50032:140FBF8583171010A4260000, 0.35180:0A00D330, 255.23226:A9260000, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:B3260000, 4.21921:DC040000, 255.27962:FA000000, 255.1494:0A007530, 0.37692:02010480, 0.44092:00000000, 0.40348:02010480, 0.34608:04000100, 0.55056:00000000, 0.42768:302E3134, 0.56112:31393A44, 0.52807:30363031, 4.33016:DC040000, 7.40748:010000000000010B2D343438, 7.57132:000000000000000037323032,
What is missing?
The important part from the error is the phrase "SendAsDenied".
Office 365 won't let you use your account on their smtp servers to send e-mail messages from someone else's address. You just can't do it. The closest you can get is in cases of organizational domain accounts, you can sometimes have service accounts within the organization that can be delegated to send on behalf of other users within the organization's domain.
If you need to do more than that, you must manage your own smtp server... and let me tell you, that's a whole other can of worms, requiring an ability to understand and configure some or all of rDNS, SPF, DKIM, Domain-Keys, and DMARC.
I have the following action method to send emails using gmail smtp:-
[HttpPost]
public ActionResult Contact(Contact c)
{
//
if (ModelState.IsValid)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("*****");
mail.To.Add(new MailAddress("******"));
mail.Subject = "New Feedback from Edama Web Site";
mail.IsBodyHtml = true;
System.Text.StringBuilder mailBody = new System.Text.StringBuilder();
mailBody.AppendLine("<b>Dear Sirs, </b><br/><br/>");
mail.Body = mailBody.ToString();
// Create a new Smpt Client using Google's servers
var mailclient = new SmtpClient();
mailclient.Host = "smtp.gmail.com";
mailclient.Port = 587;
// This is the critical part, you must enable SSL
mailclient.EnableSsl = true;
mailclient.Credentials = new System.Net.NetworkCredential
("***", "***"); /
//Or your Smtp Email ID and Password
//smtp.EnableSsl = true;
mailclient.Send(mail);
TempData["message"] = string.Format("Your Feedback has been submitted. Thanks");
return RedirectToAction("Contact");
}
return View(c);
}
now when i am running my web application under VS 2013 everything will work well , where i will receive emails correctly. but now i deploy my web application under a hosting server , and when i call the above action method i got the following error:-
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
so what is causing this error ?
second question. i am a bit confused , as inside my action method i define the following mailclient.EnableSsl = true; does this mean that my web application should be running under https which is not my case, as my web application is a public web site so it is not under https .. and as i mentioned before when i call my action method inside VS 2013 on for example localhost:1234 the smtp send email correctly even i am not running my localhost under https ...
When using ssl over gmail smtp - the port number used in 465.
Src: https://support.google.com/a/answer/176600?hl=en
Enable SSL property while sending email does not require your application to run over ssl. Rather it specifies whether SSL is used to access the specified SMTP mail server.
I am using Office365 web app SMTP to send email from Asp.Net but Its always throwing following error!
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated at System.Net.Mail.MailCommand.CheckResponse
The web.config is given below - with username & password changed
<network enableSsl="true" host="pod51007.outlook.com" userName="XXXX" password="XXXXX" port="587" defaultCredentials="false" />
I had the same problem and solved so:
Dim client As SmtpClient = New SmtpClient()
client.Credentials = New System.Net.NetworkCredential("your user", "your password")
client.Port = 587
client.Host = "smtp.office365.com"
important are this instruction, without them is not working :
client.UseDefaultCredentials = False
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.EnableSsl = True
I think the error message is misleading (as with most Microsoft errors!) - The error code looks very simular to a SMTP error and 5.7.1 is a relay error. You may need to specify your development/production public IP address using the admin portal provided by Microsoft.
I am getting this error while sending email from my application. Can anyone suggest any solution.
Service not available, closing transmission channel. The server
response was: 4.3.2 Service not available, closing transmission
channel
Below is code.
string adminID = "AAA#tu.edu";
MailMessage msg = new MailMessage();
msg.From = new MailAddress(adminID);
msg.To.Add("BBB#ttu.edu");
msg.Subject = "Sample Email";
msg.Body = "Hello ";
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Host = "basic.smtp.ttu.edu";
SmtpMail.Port = 25;
SmtpMail.Send(msg);
Got the solution for the issue. The Server was rejecting the request because this application didn't have write rights on that server. The code was perfectly fine, just it was permissions problem. Hope this helps someone!
Please check whether the server which is sending the e-mail is whitelisted on the SMTP server or Exchange server.
I had the same issue and whitelisting it on SMTP server resolved my issue.
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. u6sm344516ibd.6
I have my code like this?
MailAddress to = new MailAddress("xxxxx#gmail.com");
MailAddress from = new MailAddress("xxx#gmail.com");
MailMessage message = new MailMessage(from, to);
message.Subject = "Error Occred in the application:";
message.Body = ex.Message;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
the SMTP server required that you use a secure connection
client.EnableSsl = true;
You could check if setting the EnableSsl property for SmtpClient to true and specifying the credentials would help.
client.EnableSsl = true;
client.Credentials = new NetworkCredential("user", "password");
You will need to set the appropriate properties of the SmtpClient instance to enable TSL/SSL, and set credentials. Check out this for more:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
Try configuring your SMTP to use port 25 (with SSL).
For gmail Smtp server, use port 587. Port 465 has problems. Make sure you also pass in your correct gmail address and the password that you use with that address/account. Finally, ensure you have set your gmail account to accept connections from other email apps.