@@ -3,14 +3,17 @@ import * as App from '@app/index.ts'
33
44const etherealUser = Deno . env . get ( 'ETHEREAL_USER' )
55const etherealPass = Deno . env . get ( 'ETHEREAL_PASS' )
6+ const oauth2AccessToken = Deno . env . get ( 'SMTP_OAUTH2_ACCESS_TOKEN' )
67const runSecureSmtpTest = Deno . env . get ( 'RUN_SECURE_SMTP_TEST' ) === 'true'
8+ const runOAuth2SmtpTest = Deno . env . get ( 'RUN_OAUTH2_SMTP_TEST' ) === 'true'
79const hasEtherealCredentials = Boolean ( etherealUser && etherealPass )
810
911const smtpConfig = {
1012 host : 'smtp.ethereal.email' ,
1113 port : 587 ,
1214 secure : false ,
1315 auth : {
16+ type : 'password' as const ,
1417 user : etherealUser ?? '' ,
1518 pass : etherealPass ?? ''
1619 }
@@ -21,11 +24,23 @@ const secureSmtpConfig = {
2124 port : 465 ,
2225 secure : true ,
2326 auth : {
27+ type : 'password' as const ,
2428 user : etherealUser ?? '' ,
2529 pass : etherealPass ?? ''
2630 }
2731}
2832
33+ const oauth2SmtpConfig = {
34+ host : 'smtp.ethereal.email' ,
35+ port : 587 ,
36+ secure : false ,
37+ auth : {
38+ type : 'oauth2' as const ,
39+ user : etherealUser ?? '' ,
40+ accessToken : oauth2AccessToken ?? ''
41+ }
42+ }
43+
2944Deno . test ( 'create transporter with Ethereal SMTP config' , ( ) => {
3045 if ( ! hasEtherealCredentials ) {
3146 return
@@ -185,3 +200,16 @@ Deno.test('send email with string attachment content and 7bit encoding', async (
185200 ]
186201 } )
187202} )
203+
204+ Deno . test ( 'send email over oauth2 configuration' , async ( ) => {
205+ if ( ! etherealUser || ! oauth2AccessToken || ! runOAuth2SmtpTest ) {
206+ return
207+ }
208+ const sender = App . mailer . transporter ( oauth2SmtpConfig )
209+ await sender . send ( {
210+ from : `Mailer Integration <${ etherealUser } >` ,
211+ to : `Mailer Integration <${ etherealUser } >` ,
212+ subject : 'Deno-Mailer oauth2 integration test' ,
213+ text : 'OAuth2 send test'
214+ } )
215+ } )
0 commit comments