Skip to content

Commit 9bb2807

Browse files
authored
TASk-3786: outbound_smtp_auth supporting XOAUTH2 (#792)
1 parent fdd0ebf commit 9bb2807

File tree

3 files changed

+150
-31
lines changed

3 files changed

+150
-31
lines changed

content/momentum/4/modules/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
lastUpdated: "03/01/2025"
2+
lastUpdated: "05/30/2025"
33
title: "Category File"
44
type: "custom"
55
name: "Modules Reference"
@@ -63,7 +63,7 @@ description: "Table of Contents 71 1 Introduction 71 2 ac auth Authentication Ha
6363
| [openarc](/momentum/4/modules/openarc) | Open Source ARC |
6464
| [opendkim](/momentum/4/modules/opendkim) | Open Source DKIM |
6565
| [outbound_audit](/momentum/4/modules/outbound-audit) | Outbound traffic analytics |
66-
| [outbound_smtp_auth(modules.outbound_smtp_auth.php) |
66+
| [outbound_smtp_auth](/momentum/4/modules/outbound-smtp-auth) | Outbound authentication |
6767
| [persist_io](/momentum/4/modules/persistio) | Persistent IO Wrapper |
6868
| [pipe_io](/momentum/4/modules/pipeio) | Pipe IO Wrapper |
6969
| [pipe_transport](/momentum/4/modules/pipe-transport) | Module |
Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,94 @@
11
---
2-
lastUpdated: "03/26/2020"
2+
lastUpdated: "05/30/2025"
33
title: "outbound_smtp_auth"
4-
description: "This module enables users to specify authentication parameters for a given set of messages so that Momentum will authenticate against the peer server when it sends outbound mail It currently supports the AUTH LOGIN and AUTH PLAIN methods of authentication You can specify the parameters in configuration or in lua..."
4+
description: "This module enables users to specify authentication parameters for a given set of messages so that Momentum will authenticate against the peer server when it sends outbound mail It currently supports the AUTH LOGIN, AUTH PLAIN and AUTH XOAUTH2 methods of authentication You can specify the parameters in configuration or in lua..."
55
---
66

7-
<a name="idp22419360"></a>
7+
<a name="modules.outbound_smtp_auth"></a>
88

9-
This module enables users to specify authentication parameters for a given set of messages so that Momentum will authenticate against the peer server when it sends outbound mail. It currently supports the 'AUTH LOGIN' and 'AUTH PLAIN' methods of authentication. You can specify the parameters in configuration or in lua, or use a combination of both.
9+
This module enables users to specify authentication parameters for a given set of messages so that
10+
Momentum will authenticate against the peer server when it sends outbound mail. It currently
11+
supports the `AUTH LOGIN`, `AUTH PLAIN` and `AUTH XOAUTH2` methods of authentication.
12+
You can specify the parameters in configuration or in lua, or use a combination of both.
1013

1114
### Note
1215

1316
This module makes heavy use of message contexts to facilitate authentication. If it is enabled, you risk having extra I/O unless `keep_message_dicts_in_memory` is on.
1417

15-
**Configuration Change. ** This feature is available in Momentum 4.2 and later.
18+
**Configuration Change** This module is refactored in Momentum 5.1, but this feature is available in
19+
Momentum 4.2 and later. `AUTH XOAUTH2` support is added in 5.1.
1620

1721
### <a name="modules.outbound_smtp_auth.configuration"></a> Configuration
1822

19-
Configuration variables are listed below. These values can all be changed and overridden by setting context variables with the same name as the options in lua. All variables are valid in the binding group, binding, domain, and global scopes.
23+
Configuration variables are listed below. These values can all be changed and overridden by setting
24+
message context variables with the same name as the options in lua.
25+
All variables are valid in the binding group, binding, domain, and global scopes.
2026

2127
<dl class="variablelist">
2228

23-
<dt>outbound_smtp_auth_key</dt>
24-
25-
<dd>
26-
27-
A unique key that can be used in lua to look up authorization details in a database. It enables you to easily trigger custom behavior based on a configuration scope. The default value is `false`.
28-
29-
</dd>
30-
3129
<dt>outbound_smtp_auth_pass</dt>
3230

3331
<dd>
3432

35-
The password that will be passed to the remote server. The default value is `false`.
33+
The password or auth token (e.g. for `AUTH XOAUTH2`) that will be passed to the remote server.
34+
It has no default value.
3635

3736
### Note
3837

39-
Setting the password in configuration will leave it as plaintext. To set the password more securely, dynamically retrieve it from a data store in lua and set it in the context variable that corresponds to this option.
38+
Setting the password in configuration will leave it as plaintext.
39+
To set the password more securely, it's recommended to dynamically retrieve it from a data store
40+
in lua and set it in the context variable that corresponds to this option.
4041

4142
</dd>
4243

4344
<dt>outbound_smtp_auth_type</dt>
4445

4546
<dd>
4647

47-
Determines what authentication protocol should be used. The only supported values are 'PLAIN' and 'LOGIN'. The default value is `false`.
48+
Determines what authentication protocol should be used. The only supported values are `PLAIN`,
49+
`LOGIN` and `XOAUTH2`. It has no default value.
4850

4951
</dd>
5052

5153
<dt>outbound_smtp_auth_user</dt>
5254

5355
<dd>
5456

55-
The username that will be passed to the remote server. The default value is `false`.
57+
The username that will be passed to the remote server. It has no default value.
5658

5759
</dd>
5860

5961
</dl>
6062

6163
### <a name="modules.outbound_smtp_auth.usage"></a> Usage
6264

65+
A hook `outbound_smtp_auth_config(msg)` is added by this module to allow per message auth settings.
66+
The settings in `ec_message` context will override the configuration values.
67+
This hook is called in delivery/scheduler thread before sending SMTP `AUTH` command.
68+
Please avoid blocking or lengthy operations when implementing this hook.
69+
6370
Basic examples of usage are provided below.
6471

65-
The following example shows how you can extend the new hook and set the username and password in lua.
72+
The following example shows how you can extend the new hook and set the username and password in lua
73+
for each message.
6674

67-
<a name="modules.outbound_smtp_auth.example.set_username_pw"></a>
75+
<a name="modules.outbound_smtp_auth.example.set_username_pw"></a>
6876

6977

7078
```
71-
function mod:outbound_smtp_auth_config(msg, ac, vctx)
72-
print('NOTICE: outbound_smtp_auth_config Lua hook called');
73-
print('NOTICE: msg:['.. tostring(msg) ..']')
74-
msg:context_set(VCTX_MESS, 'outbound_smtp_auth_user', 'foo')
75-
msg:context_set(VCTX_MESS, 'outbound_smtp_auth_pass', 'bar')
79+
function mod:outbound_smtp_auth_config(msg)
80+
--print('NOTICE: outbound_smtp_auth_config Lua hook called');
81+
msg:context_set(VCTX_MESS, 'outbound_smtp_auth_type', 'XOAUTH2')
82+
-- credential taken from example here:
83+
-- https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth
84+
msg:context_set(VCTX_MESS, 'outbound_smtp_auth_user', '[email protected]')
85+
msg:context_set(VCTX_MESS, 'outbound_smtp_auth_pass', 'EwBAAl3BAAUFFpUAo7J3Ve0bjLBWZWCclRC3EoAA')
7686
end
7787
```
7888

7989
The following example shows how to use the new configuration variables to set distinct authorization parameters for two different domains.
8090

81-
<a name="modules.outbound_smtp_auth.example.set_auth_parms"></a>
91+
<a name="modules.outbound_smtp_auth.example.set_auth_parms"></a>
8292

8393

8494
```
@@ -90,13 +100,17 @@ Domain "messagesystems.com" {
90100
Outbound_SMTP_AUTH_Type = "LOGIN"
91101
Outbound_SMTP_AUTH_User = "msys"
92102
Outbound_SMTP_AUTH_Pass = "msys"
93-
Outbound_SMTP_AUTH_Key = "somestring"
94103
}
95104
96105
Domain "sparkpost.com" {
97106
Outbound_SMTP_AUTH_Type = "PLAIN"
98107
Outbound_SMTP_AUTH_user = "sparkpost"
99108
Outbound_SMTP_AUTH_pass = "sparkpost"
100-
Outbound_SMTP_AUTH_Key = "someotherstring"
101109
}
102-
```
110+
111+
Domain "bird.com" {
112+
Outbound_SMTP_AUTH_Type = "XOAUTH2"
113+
Outbound_SMTP_AUTH_user = "[email protected]"
114+
Outbound_SMTP_AUTH_pass = "EwBAAl3BAAUFFpUAo7J3Ve0bjLBWZWCclRC3EoAA"
115+
}
116+
```
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
lastUpdated: "03/26/2020"
3+
title: "outbound_smtp_auth_v0"
4+
description: "This module enables users to specify authentication parameters for a given set of messages so that Momentum will authenticate against the peer server when it sends outbound mail It currently supports the AUTH LOGIN and AUTH PLAIN methods of authentication You can specify the parameters in configuration or in lua..."
5+
---
6+
7+
<a name="idp22419360"></a>
8+
9+
** This module is deprecated and replaced by the new
10+
[outbound_smtp_auth](/momentum/4/modules/outbound-smtp-auth) module since 5.1. **
11+
12+
This module enables users to specify authentication parameters for a given set of messages so that Momentum will authenticate against the peer server when it sends outbound mail. It currently supports the 'AUTH LOGIN' and 'AUTH PLAIN' methods of authentication. You can specify the parameters in configuration or in lua, or use a combination of both.
13+
14+
### Note
15+
16+
This module makes heavy use of message contexts to facilitate authentication. If it is enabled, you risk having extra I/O unless `keep_message_dicts_in_memory` is on.
17+
18+
**Configuration Change. ** This feature is available in Momentum 4.2 and later.
19+
20+
### <a name="modules.outbound_smtp_auth_v0.configuration"></a> Configuration
21+
22+
Configuration variables are listed below. These values can all be changed and overridden by setting context variables with the same name as the options in lua. All variables are valid in the binding group, binding, domain, and global scopes.
23+
24+
<dl class="variablelist">
25+
26+
<dt>outbound_smtp_auth_key</dt>
27+
28+
<dd>
29+
30+
A unique key that can be used in lua to look up authorization details in a database. It enables you to easily trigger custom behavior based on a configuration scope. The default value is `false`.
31+
32+
</dd>
33+
34+
<dt>outbound_smtp_auth_pass</dt>
35+
36+
<dd>
37+
38+
The password that will be passed to the remote server. The default value is `false`.
39+
40+
### Note
41+
42+
Setting the password in configuration will leave it as plaintext. To set the password more securely, dynamically retrieve it from a data store in lua and set it in the context variable that corresponds to this option.
43+
44+
</dd>
45+
46+
<dt>outbound_smtp_auth_type</dt>
47+
48+
<dd>
49+
50+
Determines what authentication protocol should be used. The only supported values are 'PLAIN' and 'LOGIN'. The default value is `false`.
51+
52+
</dd>
53+
54+
<dt>outbound_smtp_auth_user</dt>
55+
56+
<dd>
57+
58+
The username that will be passed to the remote server. The default value is `false`.
59+
60+
</dd>
61+
62+
</dl>
63+
64+
### <a name="modules.outbound_smtp_auth_v0.usage"></a> Usage
65+
66+
Basic examples of usage are provided below.
67+
68+
The following example shows how you can extend the new hook and set the username and password in lua.
69+
70+
<a name="modules.outbound_smtp_auth_v0.example.set_username_pw"></a>
71+
72+
73+
```
74+
function mod:outbound_smtp_auth_v0_config(msg, ac, vctx)
75+
print('NOTICE: outbound_smtp_auth_v0_config Lua hook called');
76+
print('NOTICE: msg:['.. tostring(msg) ..']')
77+
msg:context_set(VCTX_MESS, 'outbound_smtp_auth_user', 'foo')
78+
msg:context_set(VCTX_MESS, 'outbound_smtp_auth_pass', 'bar')
79+
end
80+
```
81+
82+
The following example shows how to use the new configuration variables to set distinct authorization parameters for two different domains.
83+
84+
<a name="modules.outbound_smtp_auth_v0.example.set_auth_parms"></a>
85+
86+
87+
```
88+
outbound_smtp_auth_v0 { }
89+
90+
Keep_Message_Dicts_In_Memory = true
91+
92+
Domain "messagesystems.com" {
93+
Outbound_SMTP_AUTH_Type = "LOGIN"
94+
Outbound_SMTP_AUTH_User = "msys"
95+
Outbound_SMTP_AUTH_Pass = "msys"
96+
Outbound_SMTP_AUTH_Key = "somestring"
97+
}
98+
99+
Domain "sparkpost.com" {
100+
Outbound_SMTP_AUTH_Type = "PLAIN"
101+
Outbound_SMTP_AUTH_user = "sparkpost"
102+
Outbound_SMTP_AUTH_pass = "sparkpost"
103+
Outbound_SMTP_AUTH_Key = "someotherstring"
104+
}
105+
```

0 commit comments

Comments
 (0)