Examining the log, I see some of these errors:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at YAF.Classes.Core.YafSendMail.Send(MailAddress fromAddress, MailAddress toAddress, String subject, String bodyText, String bodyHtml) in D:\Web Sites\YAF195Rc1\YAF.Classes\YAF.Classes.Core\Services\YafSendMail.cs:line 216
This seems to be random but once it happen, it would happen over and over again until sometime later where it would magically start working again. When this error happen, user X can't email user Y using the "Email" feature. I'm not sure if new members can sign up (if required email verification).
I fixed this problem by adding the lines in yellow.
public void Send(
[NotNull] MailAddress fromAddress,
[NotNull] MailAddress toAddress,
[CanBeNull] string subject,
[CanBeNull] string bodyText,
[CanBeNull] string bodyHtml)
{
CodeContracts.ArgumentNotNull(fromAddress, "fromAddress");
CodeContracts.ArgumentNotNull(toAddress, "toAddress");
using (var emailMessage = new MailMessage())
{
emailMessage.To.Add(toAddress);
emailMessage.From = fromAddress;
emailMessage.Subject = subject;
Encoding textEncoding = Encoding.UTF8;
// TODO: Add code that figures out encoding...
/*
if ( !Regex.IsMatch( bodyText, @"^([0-9a-z!@#\$\%\^&\*\(\)\-=_\+])", RegexOptions.IgnoreCase ) ||
!Regex.IsMatch( subject, @"^([0-9a-z!@#\$\%\^&\*\(\)\-=_\+])", RegexOptions.IgnoreCase ) )
{
textEncoding = Encoding.Unicode;
}
*/
// add text view...
emailMessage.AlternateViews.Add(
AlternateView.CreateAlternateViewFromString(bodyText, textEncoding, "text/plain"));
// see if html alternative is also desired...
if (bodyHtml.IsSet())
{
emailMessage.AlternateViews.Add(
AlternateView.CreateAlternateViewFromString(bodyHtml, Encoding.UTF8, "text/html"));
}
// Wes : Changed to use settings from configuration file's standard <smtp> section.
// Reason for change: The host smtp settings are redundant and
// using them here couples this method to YafCache, which is dependant on a current HttpContext.
// Configuration settings are cached automatically.
var smtpSend = new SmtpClient { EnableSsl = Config.UseSMTPSSL };
//Tommy: solve random failture problem. Don't set this value to 1.
//See this: http://stackoverflow.com...stem-net-mail-has-issues
smtpSend.ServicePoint.MaxIdleTime = 2; smtpSend.Send(emailMessage);
}
}