smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
584 stars 178 forks source link

Missing SMTP host exception despite using SpecifiedPickupDirectory #31

Open JustinStolle opened 12 years ago

JustinStolle commented 12 years ago

When using SpecifiedPickupDirectory as the deliveryMethod in Web.config for testing (rather than Network with a host value), an InvalidOperationException is thrown with the message "The SMTP host was not specified."

at System.Net.Mail.SmtpClient.CheckHostAndPort() at System.Net.Mail.SmtpClient.get_ServicePoint() at System.Net.Mail.SmtpClient.Dispose(Boolean disposing) at System.Net.Mail.SmtpClient.Dispose() at Mvc.Mailer.SmtpClientWrapper.Send(MailMessage mailMessage) at Mvc.Mailer.MailMessageExtensions.Send(MailMessage message, ISmtpClient smtpClient) at MySite.Controllers.UsersController.ResetPassword(String userName)

JustinStolle commented 12 years ago

The message does get "sent" to the specified pickup directory even though this error is thrown, but I'd prefer not to have to catch an InvalidOperationException just to ignore it.

JustinStolle commented 12 years ago

The workaround to this bug (that is closed as fixed, see this item) is to add <network host="localhost" /> (using "localhost" or any other value) to Web.config, but I'm curious if you think adding any handling code to the overridden Send method in SmtpClientWrapper class would be advised.

<system.net>
  <mailSettings>
    <smtp from="notify@domain.com" deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="C:\temp\EmailPickup\" />
      <network host="localhost" />
    </smtp>
  </mailSettings>
</system.net>