The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required

Using the default Email Action item for Workflow action in Sitecore 7.2 takes the following parameters:

  1. To (To Email)
  2. From (From Email)
  3. Subject
  4. Message (Body)
  5. Mail Server (Host)
  6. Type (default: Sitecore.Workflows.Simple.EmailAction, Sitecore.Kernel)
If the mail server uses authentication, which most email hosts do, you get the following error:


The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required

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.7.1 Authentication required

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.


This occurs even if you the following settings configured in your Web.Config:

 <setting name="MailServer" value="somehost"/>
 <setting name="MailServerUserName" value="username"/>
 <setting name="MailServerPassword" value="password"/>
 <setting name="MailServerPort" value="2525"/>

Looks like the EmailAction class simply ignores the SMTP settings and the smtp client tries to send an email based on the fields in the Email Action, which obviously do not contain the credentials.

The only way I could get this to work was to write a custom email action pipeline processor as shown here by FISH TANK.
The critical change to this implementation was to pass the network credentials and port as follows:
var smtpClient = new SmtpClient(host);
smtpClient.Credentials = new NetworkCredential(Settings.GetSetting("MailServerUserName"), Settings.GetSetting("MailServerPassword"));
int port;
smtpClient.Port = int.TryParse(Settings.GetSetting("MailServerPort"), out port)? port:25;
try
{
     smtpClient.Send(message);
}
catch (Exception ex)
{
    Sitecore.Diagnostics.Log.Error(ex.Message,ex);
}
 PS: Apparently there is also this Enhanced Email Action module that is supported until 6.5

Comments

Popular posts from this blog

Is Rendered Item Valid XHtml Document Could not find schema information warnings during publish item Sitecore 7.2

Sitecore Tabbed Select Rendering dialog

RESOLVED: Solr Exceptions - Document contains at least one immense term in field