45 connection.
setHeader(
"content-type",
"text/plain; charset=utf-8");
47 resp <<
"SMTP time: ";
48 time_t currentTime = time(
nullptr);
50 localtime_r(¤tTime, <ime);
51 resp << put_time(<ime,
"%a, %e %b %Y %H:%M:%S %z") <<
"\r\n\r\n";
54 auto replacementRules = make_shared<ReplacementRules>();
55 replacementRules->insert({
"Test",
"T€st"});
56 replacementRules->insert({
"email",
"émail"});
62 resp <<
"+++++ TEST 1: SimpleEmail +++++\r\n\r\n";
67 email1.
headers()[
"Content-Type"] =
"text/plain; charset=utf-8";
69 email1.
text() =
"Test email 'm€ssage' =@#$%^&*()===";
70 resp << email1.
getRaw(replacementRules) <<
"\r\n\r\n";
73 resp <<
"+++++ TEST 2: MimeEmail +++++\r\n\r\n";
78 email2.
headers()[
"Subject"] =
"Test email 2";
82 textPart.
applyEncoding() = MimeEmail::MimePart::ApplyEncoding::QUOTED_PRINTABLE;
83 textPart.
contentType() =
"text/plain; charset=utf-8";
85 textPart.
partData() =
"Test email 'm€ssage' =@#$%^&*()=== asjdflkasjdfoiwej sdflkawjefijwefijsldjf dsnvndvjnwkjenggfweg";
89 htmlPart.
applyEncoding() = MimeEmail::MimePart::ApplyEncoding::QUOTED_PRINTABLE;
90 htmlPart.
contentType() =
"text/html; charset=utf-8";
93 htmlPart.
partData() =
"<html><head><title>Bla</title></head>\n<body><p>Test Täst email</p></body></html>";
97 attachmentPart.
applyEncoding() = MimeEmail::MimePart::ApplyEncoding::BASE64;
98 attachmentPart.
contentType() =
"image/png; name=test.png";
103 resp <<
"!!! Specified image file could not be loaded: " << e.
getMessage() <<
" !!!\r\n\r\n";
108 textAndHtml.
multipartType() = MimeEmail::MimePartList::MultipartType::ALTERNATIVE;
109 textAndHtml.
mimeParts().emplace_back(textPart);
110 textAndHtml.
mimeParts().emplace_back(htmlPart);
118 resp << email2.
getRaw(replacementRules);
121 if (connection.
request().
get()[
"sendit"] ==
"yes") {
126 mail::SmtpMailer smtp(
"example.com", 587, mail::SmtpMailer::TlsMode::REQUIRE_STARTTLS,
127 true,
"test@example.com",
"12345");
128 smtp.enqueue(make_shared<SimpleEmail>(email1), to, make_shared<EmailAddress>(from), replacementRules);
129 smtp.enqueue(make_shared<MimeEmail>(email2), to, make_shared<EmailAddress>(from), replacementRules);
133 resp <<
"Mail sent successfully!";
Exception class that can be used by apps to catch errors resulting from nawa function calls.
Structure representing a MIME email.
Structure representing a basic email.
For establishing a connection to an SMTP server and sending emails.
This file will be configured by CMake and contains the necessary properties to ensure that a loaded a...
void setHeader(std::string key, std::string value)
std::ostream & responseStream() noexcept
nawa::Request const & request() const noexcept
virtual std::string getMessage() const noexcept
virtual std::string getDebugMessage() const noexcept
request::GPC const & get() const noexcept
std::string get(bool includeName=true, bool applyPunycode=true) const
HeadersMap & headers() noexcept
std::vector< MimePartOrList > & mimeParts() noexcept
MultipartType & multipartType() noexcept
std::string & contentDisposition() noexcept
std::string & partData() noexcept
bool & allowReplacements() noexcept
std::string & contentType() noexcept
ApplyEncoding & applyEncoding() noexcept
MimePartList & mimePartList() noexcept
std::string getRaw(std::shared_ptr< ReplacementRules > const &replacementRules) const override
std::string getRaw(std::shared_ptr< ReplacementRules > const &replacementRules) const override
std::string & text() noexcept
int handleRequest(Connection &connection)
int init(AppInit &appInit)
Namespace containing functions for text encoding and decoding.
std::string makeEncodedWord(std::string const &input, bool base64=false, bool onlyIfNecessary=true)
std::string getFileContents(std::string const &path)
Contains useful functions that improve the readability and facilitate maintenance of the NAWA code.