I upgraded my site to 5.4.2 and a previously working function had stopped working, throwing an exception each time.
The stack trace looked like this:
Stack trace: at DotNetNuke.Services.Mail.Mail.RouteToUserMessaging(String MailFrom, String MailTo, String Cc, String Bcc, String Subject, String Body, List`1 Attachments)
at DotNetNuke.Services.Mail.Mail.SendMail(String MailFrom, String MailTo, String Cc, String Bcc, String ReplyTo, MailPriority Priority, String Subject, MailFormat BodyFormat, Encoding BodyEncoding, String Body, List`1 Attachments, String SMTPServer, String SMTPAuthentication, String SMTPUsername, String SMTPPassword, Boolean SMTPEnableSSL)
at DotNetNuke.Services.Mail.Mail.SendMail(String MailFrom, String MailTo, String Cc, String Bcc, String ReplyTo, MailPriority Priority, String Subject, MailFormat BodyFormat, Encoding BodyEncoding, String Body, String[] Attachment, String SMTPServer, String SMTPAuthentication, String SMTPUsername, String SMTPPassword, Boolean SMTPEnableSSL)
at DotNetNuke.Services.Mail.Mail.SendMail(String MailFrom, String MailTo, String Cc, String Bcc, MailPriority Priority, String Subject, MailFormat BodyFormat, Encoding BodyEncoding, String Body, String Attachment, String SMTPServer, String SMTPAuthentication, String SMTPUsername, String SMTPPassword, Boolean SMTPEnableSSL)
at DotNetNuke.Services.Mail.Mail.SendMail(String MailFrom, String MailTo, String Cc, String Bcc, MailPriority Priority, String Subject, MailFormat BodyFormat, Encoding BodyEncoding, String Body, String Attachment, String SMTPServer, String SMTPAuthentication, String SMTPUsername, String SMTPPassword)
at DotNetNuke.Services.Mail.Mail.SendMail(String MailFrom, String MailTo, String Bcc, String Subject, String Body, String Attachment, String BodyType, String SMTPServer, String SMTPAuthentication, String SMTPUsername, String SMTPPassword)
After opening up the 5.4.2 source code, I see that the RouteToUserMessaging has been used at the base level of the 'SendMail' call. So far so good. However, the problem is that this code has this call in it:
Dim fromUsersList As ArrayList = UserController.GetUsersByEmail(PortalSettings.Current.PortalId, MailFrom, -1, -1, -1)
Note the use of 'portalSettings'. Now, the portalSettings object comes from an object constructed during the Url Rewriting phase of a DNN request, and the portalSettings are stored in the request.context.
There's two problems with this :
1. When running in a service or request handler (ie .axd, .ashx), the request is ignored by the URl Rewriting and no portalsettings object is loaded into context.
2. When running in a scheduled task, no portal settings object is loaded, thus again causing the 'object not set' error.
I'm posting this here to see if there's a discussion to be had : personally I think the call should have two overloads : one including the portal id so that any non-context requests can identify the portal the call belongs to; and, if the portalSettings object is null then the call shoudl return false.
I'll rasie a gemini issue on this if that's the consensus.
|