Estoy usando el SDK de JS más reciente y no puedo enviar un correo electrónico sin formato sin un error confuso.
Aquí está mi código:
const msg = mimemessage.factory({ contentType: 'text/plain', contentTransferEncoding: 'base64', body: 'hello world' }) msg.header('From', 'Admin <hello@condobeaver.com>') msg.header('To', destination) msg.header('Subject', 'Customer service contact info') const command = new SendRawEmailCommand({ Destinations: [destination], Source: 'hello@condobeaver.com', RawMessage: { Data: msg.toString() } }) console.log(command) const response = await client.send(command) La salida del command es:
SendRawEmailCommand2 { middlewareStack: { add: [Function: add], addRelativeTo: [Function: addRelativeTo], clone: [Function: clone], use: [Function: use], remove: [Function: remove], removeByTag: [Function: removeByTag], concat: [Function: concat], applyToStack: [Function: cloneTo], resolve: [Function: resolve] }, input: { Destinations: [ 'ilia.reingold@gmail.com' ], Source: 'hello@condobeaver.com', RawMessage: { Data: 'Content-Type: text/plain\r\n' + 'Content-Transfer-Encoding: base64\r\n' + 'From: Admin <hello@condobeaver.com>\r\n' + 'To: ilia.reingold@gmail.com\r\n' + 'Subject: Customer service contact info\r\n' + '\r\n' + 'hello world' } } }Parece tener todo lo que necesito: a/desde/asunto/contenido.
Sin embargo, cuando lo ejecuto, obtengo:
InvalidParameterValue: Empty header names are illegal.
¿Qué encabezado está vacío?
El JS SDK se encarga de la codificación base64 por usted, por lo que no necesita codificar el mensaje antes de enviarlo.
const msg = mimemessage.factory({ contentType: 'text/plain', body: 'hello world' }) msg.header('From', 'Admin <hello@condobeaver.com>') msg.header('To', destination) msg.header('Subject', 'Customer service contact info') const command = new SendRawEmailCommand({ Destinations: [destination], Source: 'hello@condobeaver.com', RawMessage: { Data: msg.toString() } }) console.log(command) const response = await client.send(command) (Observe que se elimina contentTransferEncoding: 'base64' )
Si lo consigues
TypeError: Cannot read property 'byteLength' of undefined simplemente reemplace RawMessage: { Data: msg.toString() } con RawMessage: { Data: Buffer.from(msg.toString()) }