update
This commit is contained in:
@ -57,20 +57,27 @@ export class SmtpClient extends EventEmitter {
|
||||
*/
|
||||
public async sendMail(email: Email): Promise<ISmtpSendResult> {
|
||||
const startTime = Date.now();
|
||||
const fromAddress = email.from;
|
||||
const recipients = Array.isArray(email.to) ? email.to : [email.to];
|
||||
|
||||
// Extract clean email addresses without display names for SMTP operations
|
||||
const fromAddress = email.getFromAddress();
|
||||
const recipients = email.getToAddresses();
|
||||
const ccRecipients = email.getCcAddresses();
|
||||
const bccRecipients = email.getBccAddresses();
|
||||
|
||||
// Combine all recipients for SMTP operations
|
||||
const allRecipients = [...recipients, ...ccRecipients, ...bccRecipients];
|
||||
|
||||
// Validate email addresses
|
||||
if (!validateSender(fromAddress)) {
|
||||
throw new Error(`Invalid sender address: ${fromAddress}`);
|
||||
}
|
||||
|
||||
const recipientErrors = validateRecipients(recipients);
|
||||
const recipientErrors = validateRecipients(allRecipients);
|
||||
if (recipientErrors.length > 0) {
|
||||
throw new Error(`Invalid recipients: ${recipientErrors.join(', ')}`);
|
||||
}
|
||||
|
||||
logEmailSend('start', recipients, this.options);
|
||||
logEmailSend('start', allRecipients, this.options);
|
||||
|
||||
let connection: ISmtpConnection | null = null;
|
||||
const result: ISmtpSendResult = {
|
||||
@ -79,7 +86,7 @@ export class SmtpClient extends EventEmitter {
|
||||
rejectedRecipients: [],
|
||||
envelope: {
|
||||
from: fromAddress,
|
||||
to: recipients
|
||||
to: allRecipients
|
||||
}
|
||||
};
|
||||
|
||||
@ -114,8 +121,8 @@ export class SmtpClient extends EventEmitter {
|
||||
throw new Error(`MAIL FROM failed: ${mailFromResponse.message}`);
|
||||
}
|
||||
|
||||
// Send RCPT TO for each recipient
|
||||
for (const recipient of recipients) {
|
||||
// Send RCPT TO for each recipient (includes TO, CC, and BCC)
|
||||
for (const recipient of allRecipients) {
|
||||
try {
|
||||
const rcptResponse = await this.commandHandler.sendRcptTo(connection, recipient);
|
||||
if (rcptResponse.code >= 400) {
|
||||
|
Reference in New Issue
Block a user