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:
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:
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:
- To (To Email)
- From (From Email)
- Subject
- Message (Body)
- Mail Server (Host)
- 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);PS: Apparently there is also this Enhanced Email Action module that is supported until 6.5
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);
}
Comments
Post a Comment