MantisBase v0.4.9
Loading...
Searching...
No Matches
mb::MbMailer Class Reference

#include <email.h>

Inheritance diagram for mb::MbMailer:
Collaboration diagram for mb::MbMailer:

Public Member Functions

 MbMailer (const MantisBase &app)
void configure (const MbSmtpConfig &config)
void applySettings (const json &configs)
const MbSmtpConfig & config () const
bool isConfigured () const
bool send (const MbEmailMsg &message)
bool sendTest (const std::string &to)
std::string loadTemplate (const std::string &template_name, const std::unordered_map< std::string, std::string > &variables) const
bool checkRateLimit (const std::string &email, int max_per_hour=3)
const std::vector< MbEmailMsg > & sentMessages () const
void clearSentMessages ()
void clearRateLimits ()
Public Member Functions inherited from mb::MbAppMixin
 MbAppMixin (const MantisBase &app)
 Constrictor for instantiating this interface.
 MbAppMixin (MbAppMixin &&)=default
MbAppMixin & operator= (MbAppMixin &&)=delete
 MbAppMixin (const MbAppMixin &)=default
MbAppMixin & operator= (const MbAppMixin &)=delete
const MantisBase & mbApp () const
 Application that owns this service or request context.
const MbLogger & logger () const

Static Public Member Functions

static std::string verificationEmailHtml (const std::string &app_name, const std::string &verify_url)
static std::string verificationEmailText (const std::string &app_name, const std::string &verify_url)
static std::string passwordResetEmailHtml (const std::string &app_name, const std::string &reset_url)
static std::string passwordResetEmailText (const std::string &app_name, const std::string &reset_url)
static std::string loginOtpEmailHtml (const std::string &app_name, const std::string &code, int expires_minutes)
static std::string loginOtpEmailText (const std::string &app_name, const std::string &code, int expires_minutes)

Static Public Attributes

static constexpr std::string_view kTestMessage {"MantisBase: Hey, it works!"}
static constexpr std::string_view kNotConfiguredMessage

Constructor & Destructor Documentation

◆ MbMailer()

mb::MbMailer::MbMailer ( const MantisBase & app)
explicit

Member Function Documentation

◆ applySettings()

void mb::MbMailer::applySettings ( const json & configs)

Load the smtp object from application settings. An empty or incomplete host leaves the mailer unconfigured.

◆ checkRateLimit()

bool mb::MbMailer::checkRateLimit ( const std::string & email,
int max_per_hour = 3 )

◆ clearRateLimits()

void mb::MbMailer::clearRateLimits ( )

◆ clearSentMessages()

void mb::MbMailer::clearSentMessages ( )

◆ config()

const mb::MbSmtpConfig & mb::MbMailer::config ( ) const

◆ configure()

void mb::MbMailer::configure ( const MbSmtpConfig & config)

◆ isConfigured()

bool mb::MbMailer::isConfigured ( ) const

◆ loadTemplate()

std::string mb::MbMailer::loadTemplate ( const std::string & template_name,
const std::unordered_map< std::string, std::string > & variables ) const

◆ loginOtpEmailHtml()

std::string mb::MbMailer::loginOtpEmailHtml ( const std::string & app_name,
const std::string & code,
int expires_minutes )
static

◆ loginOtpEmailText()

std::string mb::MbMailer::loginOtpEmailText ( const std::string & app_name,
const std::string & code,
int expires_minutes )
static

◆ passwordResetEmailHtml()

std::string mb::MbMailer::passwordResetEmailHtml ( const std::string & app_name,
const std::string & reset_url )
static

◆ passwordResetEmailText()

std::string mb::MbMailer::passwordResetEmailText ( const std::string & app_name,
const std::string & reset_url )
static

◆ send()

bool mb::MbMailer::send ( const MbEmailMsg & message)

Deliver a message. Mock hosts (mock, localhost:0) capture it in sentMessages() and do not connect. Otherwise the message is sent over SMTP on a trantor TCP connection. Throws MbException on validation errors, rate limits, or delivery failure.

◆ sendTest()

bool mb::MbMailer::sendTest ( const std::string & to)

Send a fixed "Hey, it works!" message to to. Throws MbException when SMTP is not configured, the address is invalid, the rate limit is exceeded, or delivery fails.

◆ sentMessages()

const std::vector< mb::MbEmailMsg > & mb::MbMailer::sentMessages ( ) const

Messages captured by the mock transport.

◆ verificationEmailHtml()

std::string mb::MbMailer::verificationEmailHtml ( const std::string & app_name,
const std::string & verify_url )
static

◆ verificationEmailText()

std::string mb::MbMailer::verificationEmailText ( const std::string & app_name,
const std::string & verify_url )
static

Member Data Documentation

◆ kNotConfiguredMessage

std::string_view mb::MbMailer::kNotConfiguredMessage
staticconstexpr
Initial value:
{
"Email service not configured. Set SMTP settings first."
}

Returned by send() and sign-in code requests when SMTP is not configured.

◆ kTestMessage

std::string_view mb::MbMailer::kTestMessage {"MantisBase: Hey, it works!"}
staticconstexpr

Subject and body used by sendTest().


The documentation for this class was generated from the following files:
  • /home/runner/work/mantisbase/mantisbase/include/mantisbase/core/email.h
  • /home/runner/work/mantisbase/mantisbase/src/core/email.cpp