tommy382
  • Posts: 91
  • Joined: 11/04/2008
Examining the log, I see some of these errors:


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);
}
}


Sponsor
Jaben
  • Posts: 2544
  • Joined: 09/10/2004
Thanks for this... wasn't aware of these issues -- but it explains the problems a bit more. I've been scratching my head. Explains why adding a Thread.Sleep() in the mail sending loop sort of fixed the problem.
tommy382
  • Posts: 91
  • Joined: 11/04/2008
The "MaxIdleTime = 1" problem is fixed in .NET 4.0 but the above code is safe even for .NET 3.5sp1.
Jaben
  • Posts: 2544
  • Joined: 09/10/2004
tommy382 wrote:

The "MaxIdleTime = 1" problem is fixed in .NET 4.0 but the above code is safe even for .NET 3.5sp1.


Well, it will be added to v1.9.5 FINAL... appreciate your input.
Forum Jump  
  • You cannot post new topics in this forum.
  • You cannot reply to topics in this forum.
  • You cannot delete your posts in this forum.
  • You cannot edit your posts in this forum.
  • You cannot create polls in this forum.
  • You cannot vote in polls in this forum.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved