Skip to content

[Bug]: Mailkit Provider fails to send mails from a scheduled JOB #7052

@miguelvaz78

Description

@miguelvaz78

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

I have code that sends emails from a scheduler client job. This Jobs, as far as I know do not have HTTP Context, so, no user or portal exists.

In the commit 93542f2 on the MailKitMailProvider.cs, on the ParseSmtpServer method, the line 143 expects a current context and this is throwing a Object Reference Null.
var currentPortalId = PortalSettings.Current.PortalId;
93542f2#diff-ad437d13d3c1a2d722f3b06c8f91d20188f99e10ff85515986b33673c43d2cc1

Steps to reproduce?

Configure the system to use MailKit
Create a scheduler job that sends emails.
When running this will breat on each SendEmail call

Current Behavior

No response

Expected Behavior

Could we assume the root portal (zero) is the one running the code when using a scheduller client?

var currentPortalId=0;
Try{
currentPortalId = PortalSettings.Current.PortalId;
}
catch{}

Relevant log output

Message:There is a problem with the configuration of your SMTP Server. Mail was not sent. Object reference not set to an instance of an object. 

Message:Object reference not set to an instance of an object.

StackTrace:

   at DotNetNuke.Services.Mail.CoreMailProvider.CreateMailMessage(IMailSettings mailSettings, IHostSettings hostSettings, MailInfo mailInfo, SmtpInfo smtpInfo)
   at DotNetNuke.Services.Mail.CoreMailProvider.SendMail(MailInfo mailInfo, SmtpInfo smtpInfo)
   at DotNetNuke.Services.Mail.Mail.SendMail(String mailFrom, String mailSender, String mailTo, String cc, String bcc, String replyTo, MailPriority priority, String subject, MailFormat bodyFormat, Encoding bodyEncoding, String body, ICollection`1 attachments, String smtpServer, String smtpAuthentication, String smtpUsername, String smtpPassword, Boolean smtpEnableSSL)

Anything else?

No response

Affected Versions

10.2.2 (latest v10 release)

What browsers are you seeing the problem on?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions