In a plugin development discussion, jordan1909 is trying to send a custom email notification when a full user is created via email parsing. They initially attempted to use Discourse’s core email system with Email::Sender.new(message, :admin_login).send, but encountered a NoMethodError because Mail::Message lacks deliver_now. After modifying sender.rb to use deliver instead, the email partially worked in development. gerhard advised sending emails via a Sidekiq job and reusing Discourse’s build_email method from existing mailers (like admin_confirmation_mailer.rb) for proper integration. They also suggested adding a custom template to the plugin’s locale file. This approach ensures compatibility with Discourse’s email infrastructure rather than manually calling SendGrid or modifying core files. jordan1909 is seeking guidance on correct usage and best practices for plugin-reusable email sending.
In my plugin I am parsing all cc’d/bcc’d users and adding them to the topic they were cc’d on. This works well for both initial emails and forwarded replies. Based on a site setting I either create a full user or a staged email user. Where I have hit a snag is if I create a full user, I want to send an email saying: “hey a user was created … etc”
I can manually post to my sendgrid api and do this but that isn’t very good for a reusable plugin, is there any way to customize an email message and send directly from the discourse core?
Ok so I kind of got something working but I can’t figure out what is incorrect here, I’d appreciate any input.
If I do this:
def self.send_user_email(address)
message = Mail::Message.new(from: "from@fromEmail.com", to: address, body: "body would go here controlled by var")
Email::Sender.new(message, :admin_login).send //I used admin_login as according to the spec it should send even if email is disabled.
end
When I do this however I am getting an error.
If I run the code above natively I see:
NoMethodError - undefined method deliver_now' for #<Mail::Message:0x007fa1bf157300> Did you mean? deliver: mail (2.6.6) lib/mail/message.rb:1379:in method_missing’
So if I go and update line 184 of the sender.rb file to be: @message.deliver instead of deliver_now I am able to get it to kinda try to send an email on my development environment.