Skip to content

Commit 6fd66ad

Browse files
committed
email_lib: offer STARTTLS mode for outgoing SMTP
References: DESK-3469
1 parent 068c2e6 commit 6fd66ad

File tree

6 files changed

+40
-29
lines changed

6 files changed

+40
-29
lines changed

doc/delivery.8gx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ should be used.
3636
Default: \fI0\fP
3737
.TP
3838
\fBoutgoing_smtp_url\fP
39-
The SMTP server to use for outgoing mails. To use the local maildrop queue, set
40-
the value to \fIsendmail://localhost\fP. smtp:// is unqueued(!), and if the
41-
SMTP server is offline, submissions cannot be carried out.
42-
.br
43-
Default: \fIsendmail://localhost\fP
39+
See gromox.cfg(5):outgoing_smtp_url.
4440
.SH Configuration directives (delivery.cfg)
4541
The following directives are recognized when reading from
4642
/etc/gromox/delivery.cfg, or when the \fB\-c\fP option is used to specify a

doc/ews.4gx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@ The ews(4gx) plugin handles all requests to the \fB/EWS/Exchange.asmx\fP
88
URI path.
99
.SH Configuration directives (gromox.cfg)
1010
The following directives are recognized when they appear in
11-
/etc/gromox/gromox.cfg.
12-
.TP
13-
\fBoutgoing_smtp_url\fP
14-
The SMTP server to use for outgoing mails. To use the local maildrop queue, set
15-
the value to \fIsendmail://localhost\fP. smtp:// is unqueued(!), and if the
16-
SMTP server is offline, submissions will be rejected (and mails stick around in
17-
Outbox or whatever folder they were submitted from).
18-
.br
19-
Default: \fIsendmail://localhost\fP
11+
/etc/gromox/gromox.cfg: outgoing_smtp_url. See the gromox.cfg(5) manpage.
2012
.SH Configuration directives (ews.cfg)
21-
The following directives are recognized when they appear in etc/gromox/ews.cfg.
13+
The following directives are recognized when they appear in
14+
/etc/gromox/ews.cfg.
2215
.TP
2316
\fBews_experimental\fP
2417
Default: \fI0\fP

doc/exchange_emsmdb.4gx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ somewhere between Unix compress(1) and gzip level 1.
3131
Default: \fI0\fP
3232
.TP
3333
\fBoutgoing_smtp_url\fP
34-
The SMTP server to use for outgoing mails. To use the local maildrop queue, set
35-
the value to \fIsendmail://localhost\fP. smtp:// is unqueued(!), and if the
36-
SMTP server is offline, submissions will be rejected (and mails stick around in
37-
Outbox or whatever folder they were submitted from).
38-
.br
39-
Default: \fIsendmail://localhost\fP
34+
See gromox.cfg(5):outgoing_smtp_url.
4035
.SH Configuration directives (exchange_emsmdb.cfg)
4136
The following directives are recognized when they appear in
4237
/etc/gromox/exchange_emsmdb.cfg.

doc/gromox.cfg.5

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ cannot be lower than 4s. The special value 0 disabled RPC timeout checking.
5454
.br
5555
Default: \fI0\fP
5656
.TP
57+
\fBoutgoing_smtp_url\fP
58+
The SMTP server to use for outgoing mails. To use the local maildrop queue, set
59+
the value to \fIsendmail://localhost\fP. smtp:// is unqueued(!), and if the
60+
SMTP server is offline, submissions will be rejected (and mails stick around in
61+
Outbox or whatever folder they were submitted from). For STARTTLS, use
62+
smtp+tls://, and for ignoring TLS certificate validation,
63+
smtp+unverifiedtls://.
64+
.br
65+
Default: \fIsendmail://localhost\fP
66+
.TP
5767
\fBruleproc_debug\fP
5868
Make the "TWOSTEP" Client-Side Inbox Rule Processor emit information about the
5969
conditions it is evaluating and the actions it is carrying out. The surrounding

doc/zcore.8gx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ custom file:
3737
In gromox-zcore, this is treated as an alias for zcore_fd_limit.
3838
.TP
3939
\fBoutgoing_smtp_url\fP
40-
The SMTP server to use for outgoing mails. To use the local maildrop queue, set
41-
the value to \fIsendmail://localhost\fP. smtp:// is unqueued(!), and if the
42-
SMTP server is offline, submissions will be rejected (and mails stick around in
43-
Outbox or whatever folder they were submitted from).
44-
.br
45-
Default: \fIsendmail://localhost\fP
40+
See gromox.cfg(5):outgoing_smtp_url.
4641
.TP
4742
\fBzcore_fd_limit\fP
4843
Request that the file descriptor table be at least this large. The magic value

lib/email/send.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <vmime/mailboxList.hpp>
1212
#include <vmime/message.hpp>
1313
#include <vmime/net/transport.hpp>
14+
#include <vmime/security/cert/defaultCertificateVerifier.hpp>
1415
#include <vmime/utility/inputStreamStringAdapter.hpp>
1516
#include <gromox/mail.hpp>
1617
#include <gromox/mail_func.hpp>
@@ -70,6 +71,27 @@ ec_error_t cu_rcpt_to_list(const TPROPVAL_ARRAY &props, const char *org_name,
7071
return ecServerOOM;
7172
}
7273

74+
static vmime::shared_ptr<vmime::net::transport> make_transport(const char *url)
75+
{
76+
vmime::utility::url vurl(url);
77+
bool uv = strncmp(url, "smtp+unverifiedtls:", 9) == 0;
78+
bool tls = uv || strncmp(url, "smtp+tls:", 9) == 0;
79+
if (tls)
80+
vurl.setProtocol("smtp");
81+
auto xp = vmime::net::session::create()->getTransport(std::move(vurl));
82+
if (!tls)
83+
return xp;
84+
xp->setProperty("connection.tls", true);
85+
if (!uv)
86+
return xp;
87+
88+
struct uv_impl : public vmime::security::cert::certificateVerifier {
89+
void verify(const vmime::shared_ptr<vmime::security::cert::certificateChain> &chain, const std::string &host) {}
90+
};
91+
xp->setCertificateVerifier(vmime::make_shared<uv_impl>());
92+
return xp;
93+
}
94+
7395
ec_error_t cu_send_mail(MAIL &mail, const char *smtp_url, const char *sender,
7496
const std::vector<std::string> &rcpt_list) try
7597
{
@@ -97,7 +119,7 @@ ec_error_t cu_send_mail(MAIL &mail, const char *smtp_url, const char *sender,
97119
content.clear();
98120
vmime::shared_ptr<vmime::net::transport> xprt;
99121
try {
100-
xprt = vmime::net::session::create()->getTransport(vmime::utility::url(smtp_url));
122+
xprt = make_transport(smtp_url);
101123
/* vmime default timeout is 30s */
102124
xprt->connect();
103125
} catch (const vmime::exception &e) {
@@ -140,7 +162,7 @@ ec_error_t cu_send_vmail(vmime::shared_ptr<vmime::message> msg,
140162
vrcpt_list.appendMailbox(vmime::make_shared<vmime::mailbox>(r));
141163
vmime::shared_ptr<vmime::net::transport> xprt;
142164
try {
143-
xprt = vmime::net::session::create()->getTransport(vmime::utility::url(smtp_url));
165+
xprt = make_transport(smtp_url);
144166
/* vmime default timeout is 30s */
145167
xprt->connect();
146168
} catch (const vmime::exception &e) {

0 commit comments

Comments
 (0)