Closed freitasjuciel closed 9 months ago
Hey @freitasjuciel thanks for opening the issue. I have not been able to reproduce your issue, is it possible to provide what emailThread.email
is? If it's not a string that could be what the issue is. Here's the code I tried and it worked just fine:
const Nylas = require("nylas");
const { default: Draft } = require('nylas/lib/models/draft');
Nylas.config({
clientId: "CLIENT_ID",
clientSecret: "CLIENT_SECRET",
});
const nylas = Nylas.with("ACCESS_TOKEN");
const draft = new Draft(nylas, {
subject: "Hello from Nylas",
body: "Hello world",
to: [{ email: "you@test.com" }],
from: [{ name: "me", email: "me@test.com" }],
})
draft.send().then((result) => {
console.log(result);
});
Any more details would be appreciated!
I can see the same issue by executing this code:
const { to, subject, body, reply_to_message_id, email_address } =
event.body;
console.log('>>> to', to);
const draft = new Draft(nylas, {
from: [{ email: email_address }],
to: [{ email: to }],
subject: subject,
body: body,
replyToMessageId: reply_to_message_id,
});
And here is the console output:
>>> to you@gmail.com
Bad Request: No recipients specified
at null.e (/Users/dimach/workspace/app-api/node_modules/nylas/lib/models/nylas-api-error.js:31:28)
at null.<anonymous> (/Users/dimach/workspace/app-api/node_modules/nylas/lib/nylas-connection.js:215:41)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errorMapping: {
'400': 'Bad Request',
'401': 'Unauthorized',
'402': 'Request Failed or Payment Required',
'403': 'Forbidden',
'404': 'Not Found',
'405': 'Method Not Allowed',
'409': 'Conflict',
'410': 'Gone',
'418': "I'm a Teapot",
'422': 'Sending Error',
'429': 'Too Many Requests',
'500': 'Server Error',
'502': 'Server Error',
'503': 'Server Error',
'504': 'Server Error'
},
statusCode: 400,
type: 'invalid_request_error'
}
{"level":"info","message":{"response":{"body":"No recipients specified","headers":{"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Origin":"https://dev.exacare.com","Content-Type":"text/plain","Vary":"Origin"},"statusCode":400}}}
We are still experiencing this exact issue when using the SDK to create a Draft and send. Is there any resolution here or workaround to still use a Draft object?
We are still experiencing this exact issue when using the SDK to create a Draft and send. Is there any resolution here or workaround to still use a Draft object?
I used a nylas.request
as described in the original question to workaround it
Hi @djakaitis - is this your latest code snippet?:
Nylas.config({
clientId: process.env.NYLAS_CLIENT_ID,
clientSecret: process.env.NYLAS_CLIENT_SECRET,
});
const nylas = Nylas.with(decrypt(user.nylasToken, user.nylasTokenIv));
const draft = new NylasDraft(nylas, {
subject: emailMessage.subject,
body: htmlBody.toString(),
from: [{ name: `${user.firstName} ${user.lastName}`.trim(), email: user.email }],
to: [{ email: emailThread.email }],
});
const result = await draft.send((error, data) => {
console.log(error);
console.log(data);
});
I just tested the following on my machine and it works:
// Import your dependencies
import dotenv from "dotenv/config.js";
import Nylas from "nylas";
import Draft from "nylas/lib/models/draft.js";
// Configure your Nylas client
Nylas.config({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
});
const nylas = Nylas.with(process.env.ACCESS_TOKEN);
// Create a draft email
const draft = new Draft.default(nylas, {
subject: "With Love, from Nylas",
body: "Well well well...",
to: [{ name: "Recipient name", email: process.env.RECIPIENT_ADDRESS }],
});
// Send the email
try {
const message = await draft.send();
console.log(`Message "${message.subject}" was sent with ID ${message.id}`);
} catch (err) {
console.error("Error:\n", err);
}
I receive the following message in the console:
Message "With Love, from Nylas" was sent with ID MESSAGE_ID
Here are a few steps to try to see if it helps:
process.env
values in a separate file, so run the code locally (i.e. node sendDraft.js
) using static values to ensure everything worksnylas.accounts.list().then(accounts => console.log(accounts));
Hey @djakaitis were you able to resolve the issue with @relaxedtomato's comment or are you still seeing the same issue?
Closing this issue, @djakaitis let us know if you still need help.
Hi folks,
We're experiencing the same issue as above in production, but it does work perfectly fine in dev. We implemented an API call for now, but would love to use the SDK since it works for all other elements we've implemented.
Here is the function that throws the error in prod:
import nylas from "@/lib/nylas/nylasClient"
import Draft from "nylas/lib/models/draft"
import EmailParticipant from "nylas/lib/models/email-participant"
export default async function sendMessage(draftData: {
to: EmailParticipant[]
subject?: string
body?: string
}): Promise<{ threadId: string; messageId: string }> {
const draft = new Draft(nylas, draftData)
const request = await draft.send()
const { threadId, id: messageId } = request
return { threadId, messageId }
}
Describe the bug When I try to send an email using the Draft class it returns and
No recipients specified
error. But when sending the request with the same fields it works properlyTo Reproduce Some steps involved to reproduce the bug and any code samples you can share.
Expected behavior Send the email since the from and to emails are in the body
SDK Version: 6.6.9, 6.7.0, 6.8.0
Additional context When using the request method from nylas it works properly