mirror of https://github.com/eleith/emailjs.git
smtp/client: always validate with `Message` in send
This commit is contained in:
parent
00ccfacb7c
commit
57c5258b25
|
@ -54,17 +54,7 @@ export class SMTPClient {
|
|||
msg: T,
|
||||
callback: MessageCallback<T>
|
||||
): void {
|
||||
const message =
|
||||
msg instanceof Message
|
||||
? msg
|
||||
: this._canMakeMessage(msg)
|
||||
? new Message(msg)
|
||||
: null;
|
||||
|
||||
if (message == null) {
|
||||
callback(new Error('message is not a valid Message instance'), msg);
|
||||
return;
|
||||
}
|
||||
const message = msg instanceof Message ? msg : new Message(msg);
|
||||
|
||||
const { isValid, validationError } = message.checkValidity();
|
||||
|
||||
|
@ -222,19 +212,6 @@ export class SMTPClient {
|
|||
this.smtp.connect(connect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {MessageStack} msg message stack
|
||||
* @returns {boolean} can make message
|
||||
*/
|
||||
protected _canMakeMessage(msg: MessageHeaders) {
|
||||
return (
|
||||
msg.from &&
|
||||
(msg.to || msg.cc || msg.bcc) &&
|
||||
(msg.text !== undefined || this._containsInlinedHtml(msg.attachment))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {MessageAttachment | MessageAttachment[]} attachment attachment
|
||||
|
|
|
@ -137,7 +137,7 @@ export class Message {
|
|||
* @see https://tools.ietf.org/html/rfc2822
|
||||
* @param {Partial<MessageHeaders>} headers Message headers
|
||||
*/
|
||||
constructor(headers: Partial<MessageHeaders>) {
|
||||
constructor(headers: Partial<MessageHeaders> = {}) {
|
||||
for (const header in headers) {
|
||||
// allow user to override default content-type to override charset or send a single non-text message
|
||||
if (/^content-type$/i.test(header)) {
|
||||
|
|
Loading…
Reference in New Issue