@@ -11,14 +11,6 @@ const firstEnv = (...keys) => {
1111 return undefined ;
1212} ;
1313
14- // Validate required email configuration
15- if ( ! process . env . FEEDBACK_EMAIL_FROM ) {
16- throw new Error ( 'Missing required env var: FEEDBACK_EMAIL_FROM' ) ;
17- }
18- if ( ! process . env . FEEDBACK_EMAIL_TO_TEAM ) {
19- throw new Error ( 'Missing required env var: FEEDBACK_EMAIL_TO_TEAM' ) ;
20- }
21-
2214const smtpUser = firstEnv ( 'SMTP_SENDER' , 'GRAPH_SENDER_USER' , 'FEEDBACK_EMAIL_FROM' ) ;
2315const tenantId = firstEnv ( 'AZURE_TENANT_ID' , 'TENANT_ID' ) ;
2416const clientId = firstEnv ( 'AZURE_CLIENT_ID' , 'CLIENT_ID' ) ;
@@ -75,8 +67,21 @@ async function getSmtpAccessToken() {
7567}
7668
7769const sendMailGeneric = async ( { to, from, subject, text, html, replyTo, cc, attachments } ) => {
78- if ( ! tenantId || ! clientId ) throw new Error ( 'Missing AZURE_TENANT_ID/AZURE_CLIENT_ID' ) ;
79- const accessToken = await getSmtpAccessToken ( ) ;
70+ if ( ! tenantId || ! clientId ) {
71+ console . warn ( 'feedback email disabled: missing AZURE_TENANT_ID/AZURE_CLIENT_ID (skipping send)' ) ;
72+ return ;
73+ }
74+ if ( ! from || ! smtpUser ) {
75+ console . warn ( 'feedback email disabled: missing From or SMTP user (skipping send)' ) ;
76+ return ;
77+ }
78+ let accessToken ;
79+ try {
80+ accessToken = await getSmtpAccessToken ( ) ;
81+ } catch ( e ) {
82+ console . warn ( 'smtp oauth token unavailable; skipping send. seed with device code script.' , e && e . message ? e . message : e ) ;
83+ return ;
84+ }
8085 const transporter = nodemailer . createTransport ( {
8186 host : 'smtp.office365.com' ,
8287 port : 587 ,
@@ -251,7 +256,7 @@ const sendFeedbackEmails = async ({
251256 ackTo // optional: explicit recipient for acknowledgement (null/undefined to suppress)
252257} ) => {
253258 const from = process . env . FEEDBACK_EMAIL_FROM ;
254- const teamList = process . env . FEEDBACK_EMAIL_TO_TEAM
259+ const teamList = ( process . env . FEEDBACK_EMAIL_TO_TEAM || '' )
255260 . split ( ',' )
256261 . map ( s => s . trim ( ) )
257262 . filter ( Boolean ) ;
0 commit comments