I have a validated domain, and sending a direct email via the AWS Pinpoint console works fine. However, I can't get the same to work with Boto3 send_messages.
I get {'DeliveryStatus': 'PERMANENT_FAILURE', 'StatusCode': 400, 'StatusMessage': 'Request must include message email message.'}
But I have a MessageConfiguration Default Message with a simple string for Body, and I've tried BodyOverride as well. No problems sending SMS.
I've been unable to snag an example of send_messages, and I think if I saw a working example of an email send, that'd be all I need.
Snippet:
response = ppClient.send_messages(
ApplicationId=pinpointId,
MessageRequest={
'Addresses': {
'mguard#{validateddomain}.com': {
# 'BodyOverride': 'Hello from Pinpoint!',
'ChannelType': 'EMAIL',
}
},
'MessageConfiguration': {
'DefaultMessage': {
'Body': 'Default Message for EMAIL.',
'Substitutions': {}
}
}
}
)
Related
I am trying to send an email with sendgrid in a remix action. I have verified that the api key is the correct environment variable. Nothing is being logged to the console at alll. Here is my code:
const sgMail = require("#sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_KEY);
const message = {
from: "admin#chriswestbrook.com",
to: "westbchris+blog#gmail.com",
subject: `a comment has been left on ${slug}`,
text: "testing",
html: `author:${author}<br/>
email:${email}<br/>
text:${text}
`,
};
try {
await sgMail.send(message);
} catch (e) {
console.log(e);
}
Am I missing something obvious?
This ended up having something to do with their indy stack using msw to mock server api requests blocking sendgrid. See this issue.
I am trying to set up an emailing system for users on my website. I am using nextJS and have an api endpoint to send emails. To send the emails I am using emailJS and sending the email to myself with a custom body. Here is the code for my email.js file:
import { SMTPClient } from 'emailjs';
export default function handler(req, res) {
const {body, subject}=req.body;
// console.log(process.env)
const client = new SMTPClient({
user: "test#gmail.com",
password: "passward",
host: 'smtp.gmail.com',
ssl:true
});
try{
client.send(
{
text: `${body}`,
from: "test#gmail.com",
to: "test#gmail.com",
subject: `${subject}`,
}
)
}
catch (e) {
res.status(400).end(JSON.stringify({ message: e.message }))
return;
}
res.status(200).end(JSON.stringify({ message:'Mail sending' }))
}
The code works when I use it on localhost but it does not work when I deploy to amplify. When I try to make a post request on amplify I get status 200 with the {"message":"Mail sending"}. However, the gmail account never gets the email. I do not get an error message. I do not have 2 step verification on and have allowed less secure apps, but still no emails are being sent. I would really appreciate any help.
The emailjs library utilizes a queuing system for sending emails. This means that the send method adds the email to the queue and sends it at a later time. This can cause issues when using the send method within a lambda function, as the function may close before the email has been sent. To ensure that the email is sent before the lambda function closes, you can use the sendAsync method instead. This method returns a promise that will be resolved when the email has been successfully sent.
To send an email using the sendAsync method, you can do the following:
await client.sendAsync(
{
text: `${body}`,
from: "test#gmail.com",
to: "test#gmail.com",
subject: `${subject}`,
}
)
In a Teams AutoAttendant you can forward the call to a Call Queue.
I am trying to achieve this same behavior with a Teams Bot.
An incoming call from the PSTN is answered by the bot.
The bot answers the call and plays a prompt.
After that the bot should transfer this call to a specific call queue!
I was able to transfer the call to a user without any trouble:
callbackUrl: process.env.WebserviceUrl + '/api/calls/notifications',
transferTarget: {
endpointType: 'default',
identity: {
user: {
id: '[User GUID]',
displayName: 'User Name'
},
}
}
Now I d'like to transfer the call to a Call Queue instead of a single user:
callbackUrl: process.env.WebserviceUrl + '/api/calls/notifications',
transferTarget: {
endpointType: 'default',
identity: {
applicationInstance: {
id: '[Application instance GUID]',
displayName: 'Call Queue XY'
},
}
}
I tried applicationInstance and application as key. I also tried with optional tenantId in the identity. Received Error is always:
403 - Forbidden
{
error: {
code: '7505',
message: 'Request authorization tenant mismatch.',
innerError: {
date: '2020-06-24T03:37:16',
'request-id': '5da7621f-dd3f-494e-a057-733e60c59bdb'
}
}
}
There is only one Tenant involved. So access key is obtained with the same tenantId as the Tenant the user and call queue are part of.
Maybe someone has a hint and can help me find the right way to achieve this.
EDIT:
Redirecting an unanswered Call to the same Call Queue works without any troubles!
If there is no way to Transfer an active call to the Queue, we will try to find a way for our use case with redirecting.
I'm trying to send emails inside next.js api functions. I have the following code:
import nodemailer, { SentMessageInfo } from "nodemailer";
export default async ({ to, subject, text, html }: Props) => {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "email-smtp.us-east-1.amazonaws.com",
port: 465,
secure: true,
auth: {
user: process.env.AWS_SES_USERNAME,
pass: process.env.AWS_SES_PASSWORD,
},
});
console.log("Sending email to", to);
// send mail with defined transport object
let info: SentMessageInfo = await transporter.sendMail({
from: '"Me" <help#myemail.io>', // sender address
to,
subject,
text,
html: html,
});
console.log("Message sent: %s", info.messageId);
return info.messageId;
};
Sometimes this can take minutes to send but I have no idea why. How would one go about debugging this? Is it possible that my Amazon SES SMTP server is throttling me? I'm not even sending emails that frequently.
I'm trying to use the new Gmail API with the Google API Node client. I created a new project from the developer console, set up a new "Service Account" Client ID, and enabled access to the API.
As a proof of concept, I am simply trying to list the threads in my inbox. When I enable the OAuth 2.0 toggle for the API explorer and enter my email address, the request succeeds and I see a JSON response with data.
Now I try to do the same in Node:
var googleapis = require('googleapis');
var SERVICE_ACCOUNT_EMAIL = '...SNIP...';
// generated by: openssl pkcs12 -in ...SNIP...p12 -out key.pem -nocerts -nodes
var SERVICE_ACCOUNT_KEY_FILE = 'key.pem';
var jwt = new googleapis.auth.JWT(
SERVICE_ACCOUNT_EMAIL,
SERVICE_ACCOUNT_KEY_FILE,
null,
['https://www.googleapis.com/auth/gmail.readonly']);
googleapis
.discover('gmail', 'v1')
.execute(function(err, client) {
jwt.authorize(function(err, result) {
if(err) console.error(err);
else console.log(result);
client.gmail.users.threads.list()
.withAuthClient(jwt)
.execute(function(err, result) {
if(err) console.error(err);
else console.log(result);
});
});
});
First I print the results of the authorize() call, which looks like it returns a token, so I think I have all the OAuth stuff setup properly:
{ access_token: '...SNIP...',
token_type: 'Bearer',
expires_in: 1404277946,
refresh_token: 'jwt-placeholder' }
Then I try to actually use the API, but I get an error:
{ errors:
[ { domain: 'global',
reason: 'backendError',
message: 'Backend Error' } ],
code: 500,
message: 'Backend Error' }
At this point, I don't know what else to try. I think the OAuth stuff is working properly, because I haven't gotten any authentication errors. I also think the API itself is working and my account is fine, because I can use it through the API Explorer. I don't see any indication that the Node library is at fault either. In short, I have no idea what the problem is. Any ideas?
You are using the Service Account to authenticate your requests to GMail. Your Service Account will not have a Gmail as far as I know, only users have GMail. For this reason you will need to do the OAuth2 flow with the user (see here for example).