1import nodemailer from 'nodemailer' 2import * as _ from 'lodash-es' 16export const getEmailProps = (props: Record<string, unknown>) => { 17 let {fromName, fromEmail} = _.merge(props, nodeMailCtx.getStore()) as Record<string, string | undefined> 18 if (isSendExceptEmailCtx.getStore()) { 19 fromName ||= 'ptemail' 22 fromEmail ||= getEnvConf().fromEmail as string | undefined 25 const gqEmailSentFromStr = `"${fromName}" <${fromEmail}>` 26 return {fromName, fromEmail, gqEmailSentFromStr} 29export const sendDaEmail = async ({ 30 mailProps, isPostmarkBroadcast=false, 32}: {mailProps: Record<string, any>, isPostmarkBroadcast?: boolean, [k: string]: unknown}) => { 33 betLog('sendDaEmail', mailProps, props) 37 const transporter = nodemailer.createTransport(transportProps) 39 const {gqEmailSentFromStr} = getEmailProps(props) 42 from: gqEmailSentFromStr, 46 const isEthereal = transportProps?.host === 'smtp.ethereal.email' 49 console.log('skipping email send for test address', mailProps.to) 50 return {gqPrevEmailUrl: null, html: mailProps.html, gqEmailSentFromStr} 55 const {text} = mailProps 56 throwIf(() => text && !_.isString(text), {text}) 57 resp = await transporter.sendMail(mailProps) 59 if (isEthereal && _.includes(ee.message, 'Invalid login: 535 Authentication failed')) { 60 console.log('clearEtherealCreds', ee) 68 gqPrevEmailUrl = nodemailer.getTestMessageUrl(resp) 69 console.log('etherealUrl', gqPrevEmailUrl) 70 if (isDevPc && !silenceEtherealCtx.getStore() && !isTestEmail(mailProps.to)) { 71 doExec(`open ${gqPrevEmailUrl}`).catch(() => {}) 75 const {html} = mailProps 76 return {gqPrevEmailUrl, html, gqEmailSentFromStr}