You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Code to test relaying mass email through primary mail server.
importtype{SMTPConnectionOptions}from'emailjs';import{Message,SMTPClient}from'emailjs';importPQueuefrom'p-queue';exporttypeAddressList={from: string;
to: string[];};/** Internal configuration used by emailjs to send mail, see https://www.npmjs.com/package/emailjs for all options. */exporttypeEmailConnectionConfig=Partial<SMTPConnectionOptions>;exportdefaultclassEmailer{/** stop sending mail after this many items are in the queue */privatereadonlymailQueueMaxSize=512;/** The minimum amount of time between sending each email. */privatereadonlyglobalMailThrottle=750;// throttle mail sending using a promise queueprivatereadonlymailQueue=newPQueue({concurrency: 1,interval: this.globalMailThrottle,intervalCap: 1});privateclient: SMTPClient;constructor(options: EmailConnectionConfig){this.client=newSMTPClient(options);}publicasyncsend(addresses: AddressList,subject: string,text: string){if(!addresses){console.warn(`Not sending email. Address list looks falsey.`);return;}constfrom=addresses.from;if(!from){console.warn(`Not sending email. No from address is configured.`);return;}if(addresses.to.length===0){console.warn(`Not sending email. No addresses are configured to send.`);return;}constto=addresses.to.join(', ');if(this.mailQueue.size>=this.mailQueueMaxSize){console.error(`Dropping outgoing email. There are currently too many items in the email queue. (Queue size= ${this.mailQueue.size}, maximum=${this.mailQueueMaxSize})`);return;}awaitnewPromise<void>(resolve=>{constmailTask=async()=>{try{console.log(`Sending email to ${to}...`);awaitthis.client.sendAsync(newMessage({
from,
to,
subject,
text,'content-type': text.startsWith('<!DOCTYPE html') ? 'text/html; charset="UTF-8"' : undefined,}));console.log(`Sending email to ${to} [SENT]`);console.log(`There are`,this.mailQueue.size,'items left in the mail queue');resolve();}catch(err){console.error('Error sending email!',`(Subject: "${subject}")`);console.error(err);console.log('Putting this email to the back of the send queue...');voidthis.mailQueue.add(mailTask);}};voidthis.mailQueue.add(mailTask);});}}
Code to test relaying mass email through primary mail server.
Source: eleith#315 (comment)
The text was updated successfully, but these errors were encountered: