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
{}};
44 auto const mid_str
= fmt::format("<{}.{}@{}>", date
.sec(),
45 pill
.as_string_view(), server_identity
);
47 fmt::memory_buffer bfr
;
48 fmt::format_to(std::back_inserter(bfr
), "Message-ID: {}\r\n",
50 fmt::format_to(std::back_inserter(bfr
), "From: \"Gene Hightower\" <{}>\r\n",
51 from
.as_string(Mailbox::domain_encoding::utf8
));
52 fmt::format_to(std::back_inserter(bfr
), "To: \"Gene Hightower\" <{}>\r\n",
53 to
.as_string(Mailbox::domain_encoding::utf8
));
54 fmt::format_to(std::back_inserter(bfr
),
55 "Subject: Testing, one, two, three.\r\n");
56 fmt::format_to(std::back_inserter(bfr
), "Date: {}\r\n", date
.c_str());
57 fmt::format_to(std::back_inserter(bfr
),
58 "Authentication-Results: {}; none\r\n", server_identity
);
59 fmt::format_to(std::back_inserter(bfr
), "MIME-Version: 1.0\r\n");
60 fmt::format_to(std::back_inserter(bfr
),
61 "Content-Type: text/plain; charset=utf-8\r\n");
63 fmt::format_to(std::back_inserter(bfr
), "\r\n");
65 fmt::format_to(std::back_inserter(bfr
), "This is the body of the email.\r\n");
66 auto const msg_str
= fmt::to_string(bfr
);
68 auto res
{DNS::Resolver
{config_path
}};
71 CHECK(snd
.mail_from_rcpt_to(res
, from
, to
, err
));
72 CHECK(snd
.send(msg_str
));