Error sending email

sharepoint2010
codeplex

#1

I have installed everything just fine and am able to add the Membership Request webpart. However, when I try to create a new user, I receive an error message and the following entry is in my logs:

System.Exception: Error sending mail notification at Visigo.Sharepoint.FormsBasedAuthentication.MembershipRequest.ApproveMembership(MembershipRequest request, SPWeb web)

I have no problem receiving outgoing emails from my site, as I have tested this with a notification. What am I missing?


#2

Make sure that the email settings are set both under Central Administration -> Outgoing Email settings, as well as on the Manage Web Applications screen.

If they are both set properly and you are still having problems, check the SharePoint log file and search for "SendEmail failed" - there should be a more detailed exception logged just before it.


#3

You may need to add the mailsettings info to your web.config of the FBA site. Here's what I have in my config:

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="email address">
        <network host="email server" port="25" />
      </smtp>
    </mailSettings>
  </system.net>

This is a child of the <configuration> tag.

-- Travis Trout


#4

Travis - I have added that to my web.config and it is still not working.

ccoulson - I have both settings working correctly.  I am still getting an error and seeing the log entries.  Here are the actual two entries that I see:

06/03/2011 13:53:39.22  w3wp.exe (0x1AE8)                        0x2B64 SharePoint Foundation          Runtime                        tkau Unexpected System.Exception: Error sending mail notification    at Visigo.Sharepoint.FormsBasedAuthentication.MembershipRequest.ApproveMembership(MembershipRequest request, SPWeb web)     at Visigo.Sharepoint.FormsBasedAuthentication.MembershipRequestControl.<>c__DisplayClass2.<OnCreatedUser>b__0()     at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()     at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)     at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)     at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)     at Visigo.Sharepoint.FormsBasedAuthentication.MembershipRequestControl.OnCreatedUser(EventArgs e)     at System.Web.UI.... c14b1faa-1304-477c-9fd4-87f453ba7fd2

06/03/2011 13:53:39.22* w3wp.exe (0x1AE8)                        0x2B64 SharePoint Foundation          Runtime                        tkau Unexpected ...WebControls.CreateUserWizard.AttemptCreateUser()     at System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e)     at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e)     at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)     at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) c14b1faa-1304-477c-9fd4-87f453ba7fd2

I reviewed the Sharepoint logs at c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Logs for the "SendEmail failed" and there is no entry.  I then searched for just SendEmail and there is no entry.  Any additional information you may have would be greatly appreciated.


#5

Usually the error can mean one of two things: There's something wrong with the SharePoint setup so it can't send the email (it uses the built in SharePoint method for sending email SPUtility.SendEmail), or there was a problem creating the email from the XSLT template (However I would have expected additional items in the log file if there were errors with the templates).  But check that the template files set in 'FBA Site Configuration' actually do exist, and are the original templates installed with the FBA Pack (in case changes to the templates have caused the error).  


#6

The MembershipApproved.xlst file is in the location c:\program files\common files\microsoft shared\web server extensions\14\template\layouts\fba\emails directory and is the original file, so that's not it.  Is there anyway I can get additional information from this exception?  I've turned on tracing at the Verbose level and it did not give me any additional information.  Is there anyway I can test the SPUtility.SendEmail function by itself?


#7

It calls another built in SharePoint method: SPUtility.IsEmailServerSet() - if that returns false then all you'll get is the exception you've been getting.  If it proceeds past that point, you should be getting some additional entries in the log file.  

If you have Visual Studio, you can pretty quickly write a small simple program that calls IsEmailServerSet and SendEmail. (Or you could use it to debug the FBA Pack and see what's going on).


#8

I agree - it's failing on IsEmailServerSet.  I setup another instance of Sharepoint on my laptop and completed the exact same config, using the same ASP.Net database and it worked just fine.  So, I know it's not authorizations.  Any idea what the code of IsEmailServerSet checking and where I can get more information?


#9

And yes, I have Visual Studio 2010, but I don't know how to debug a Sharepoint runtime object.


#10

I reflected the code on IsEmailServerSet, and it calls this on the WebApplication:

internal bool IsEmailServerSet
{
    get
    {
        SPOutboundMailServiceInstance outboundMailServiceInstance = this.OutboundMailServiceInstance;
        return outboundMailServiceInstance !null && !string.IsNullOrEmpty(outboundMailServiceInstance.Server.Address);
    }
}

So it looks like it's essentially checking the email settings that are set on the web application.  Maybe try and go into Manage Web Applications -> Outgoing Email Settings and try and change the settings, and then go back in and change them back. Maybe that will fix whatever problem there is with the setup?

As for how to debug, just grab the source code from codeplex, open it in visual studio and deploy to your server (You'll have to specify the server in the project properties).  Then just set breakpoints and start debugging.


#11

I have deleted my SMTP entries on the Farm and on the Web Application and added them back.  I still have no problems receiving alerts, but still receive the error when trying to create the user.

As far as how to debug - the solution is on my test server and my VS2010 is on my laptop.  I can't figure out how to be able to debug remotely.


#12

I've never debugged remotely (it's sounded like a real pain to get working).  I'd say save yourself the trouble and install VS 2010 on the test server.  If you do want to try and debug remotely though, I did find this blog entry:

http://lemonharpy.wordpress.com/2011/03/17/remote-debugging-sharepoint-2010-solutions/


#13

I installed VS2010 on my test server, grabbed the code from codeplex, changed the Site URL in the Project Properties to my site and then click on Build -> Deploy; however, I received the error "Error occurred in deployment step 'Retract Solution':  Attempted to perform an unauthorized operation.'  Any ideas?


#14

Disregard last post - I was able to fix it by giving my logon user Full access at the Web Application level.


#15

Well - just to let you know - the problem is fixed.  Unfortunately, I have no idea how.  I installed VS 2010 on my test server, deployed the solution, put a breakpoint where I thought it would error, and it miraculously completed without errors.  I wish I had a clue as to what fixed it, but I don't.


#16

That is very strange.  Maybe try redeploying the package downloaded from the website and see if the problem returns?


#17

I redeployed the solution and am receiving the error again.  I was able to successfully debug and found the error to be at the following line of code:

xslEmailTransform.Load(xsltTemplateFile);

The ex variable (Exception) contains the following message:  "The underlying connection was closed:  Could not establish trust relationship for the SSL/TLS secure channel."

My website is using SSL - but, I'm not quite sure what this means?


#18

Very strange. My guess is that it has something to do with how the address to the template file is built:

string.Format("{0}{1}", web.Url, settings.MembershipApprovedEmail)

Maybe web.Url is returning an http instead of https url.

Or potentially the setting for the location of the email template is incorrect (the setting is stored with the web, so it is not reset during a redeploy). For Membership Approved it should be set to:

/_layouts/FBA/emails/MembershipApproved.xslt

Check the screen shots in the documentation for all of the values.


#19

Also, does it work fine if you don't use ssl to access the site?


#20

The value of string.Format("{0}{1}", web.Url, settings.MembershipApprovedEmail is correctly set to https://{mysite}/_layouts/FBA/emails/MembershipApproved.xslt and the xslt file is located in the directory C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\FBA\EMAILS.

I will extend my site and turn off SSL to test that way and see if it works.  Additionally, the InnerException of the message is "The remote certificate is invalid according to the validation procedure".  I'm not quite sure how this could be, as I'm using my domain certificate which is issued by GoDaddy.