7 #include <fmt/format.h>
8 #include <fmt/ostream.h>
10 using namespace std::string_literals
;
12 int main(int argc
, char* argv
[])
14 std::ios::sync_with_stdio(false);
15 google::ParseCommandLineFlags(&argc
, &argv
, true);
17 auto server_identity
= [] {
18 auto const id_from_env
{getenv("GHSMTP_SERVER_ID")};
20 return std::string
{id_from_env
};
22 auto const hostname
{osutil::get_hostname()};
23 if (hostname
.find('.') != std::string::npos
)
26 LOG(FATAL
) << "can't determine my server ID, set GHSMTP_SERVER_ID maybe";
30 auto const dom_from
{Domain(server_identity
)};
31 auto const dom_to
{Domain(server_identity
)};
33 auto const config_path
= osutil::get_config_dir();
35 auto snd
{Send(config_path
, "smtp-test")};
36 snd
.set_sender(Domain(server_identity
));
38 Mailbox
from("gene", dom_from
);
39 // Mailbox to("forward", dom_to);
40 Mailbox
to("anything", dom_to
);
42 auto const date
{Now
{}};
43 auto const pill
{Pill
{}};
45 fmt::format("<{}.{}@{}>", date
.sec(), pill
, server_identity
);
47 fmt::memory_buffer bfr
;
48 fmt::format_to(bfr
, "Message-ID: {}\r\n", mid_str
.c_str());
49 fmt::format_to(bfr
, "From: \"Gene Hightower\" <{}>\r\n",
50 from
.as_string(Mailbox::domain_encoding::utf8
));
51 fmt::format_to(bfr
, "To: \"Gene Hightower\" <{}>\r\n",
52 to
.as_string(Mailbox::domain_encoding::utf8
));
53 fmt::format_to(bfr
, "Subject: Testing, one, two, three.\r\n");
54 fmt::format_to(bfr
, "Date: {}\r\n", date
.c_str());
55 fmt::format_to(bfr
, "Authentication-Results: {}; none\r\n", server_identity
);
56 fmt::format_to(bfr
, "MIME-Version: 1.0\r\n");
57 fmt::format_to(bfr
, "Content-Type: text/plain; charset=utf-8\r\n");
59 fmt::format_to(bfr
, "\r\n");
61 fmt::format_to(bfr
, "This is the body of the email.\r\n");
62 auto const msg_str
= fmt::to_string(bfr
);
64 auto res
{DNS::Resolver
{config_path
}};
67 CHECK(snd
.mail_from_rcpt_to(res
, from
, to
, err
));
68 CHECK(snd
.send(msg_str
));