Receive delivery error for failed delivery with Mailgun SMTP - mailgun

Currently, when I send mail from Mailgun SMTP, and it is not delivered, message is silently dropped and trace about it appear only in logs. It is possible to receive delivery notes when delivery failed, as in standard email accounts? (delivery notes like: This is an automatically generated Delivery Status Notification. Delivery to the following recipie... and so on)

You can get all failed mail to the mailgun by this API:
RestClient.get("https://api:YOUR-API-KEY"\
"#api.mailgun.net/v3/YOUR-DOMAIN/events",
:params => {
:'begin' => 'Fri, 3 May 2013 09:00:00 -0000',
:'ascending' => 'yes',
:'limit' => 25,
:'pretty' => 'yes',
:'event' => 'failed'
}){|response, request, result| response }

Related

Email not being sent / No errors AWS/SES

I have an AWS Lambda function:
sendEmail.js
const AWS = require('aws-sdk');
const ses = new AWS.SES();
function sendEmail(subject, message, senderEmail) {
const params = {
Destination: {
ToAddresses: [
process.env.VERIFIED_EMAIL
]
},
Message: {
Body: {
Text: {
Data: message,
Charset: 'UTF-8'
}
},
Subject: {
Data: subject,
Charset: 'UTF-8'
}
},
Source: process.env.VERIFIED_EMAIL,
ReplyToAddresses: [senderEmail]
}
return ses.sendEmail(params).promise();
}
module.exports = sendEmail;
Called from
index.js
const sendEmail = require('./sendEmail');
exports.handler = async (event, context) => {
return sendEmail(event.subject, event.message, event.email).then((response) => { context.done(null, 'Email sent')});
};
I have the env. variable VERIFIED_EMAIL set to a personal e-mail that is verified by AWS/SES.
My test case:
{
"email": "redacted#outlook.com",
"subject": "desc",
"message": "Hello!"
}
Which passes and returns "Email sent" but I don't actually receive an e-mail. I've also deployed the API-GATEWAY and I can call the API w/ Postman and I receive the same "Email sent" message but no e-mail is actually sent.
I don't think it should be an issue with being in sandbox mode because the email I am sending it from is verified.
PS:
When Looking at the SES management console it says that the emails are being sent (they take up part of the 200 daily quota) and then that none of them were bounced or rejected but simply deliveries.
A few things you should check with your SES before diving deeper.
In sandbox mode both "source email address" and "destination email address" have to be verified. Instead a mail won't be delivered.
In case you verify Email Domain so appropriate dns and DKIM records have to be added in your domain. Plus additional whitelist clearance is assumed if you use corporate domains.
Your IAM AWS user should be permitted to execute SES api calls. Check your policies and roles. Check Secret Key and Secret Id you use.
There might be problems when you use inappropriate email types and email sending endpoints (eg you try to send "SingleTemplatedMessage" via "BulkTemplatedMessage" endpoint)
Check all this things first.
Then you might try something else. In my project we use AWS SDK based on java to interact between BE and SES. It provides logs containing message statuses (if a message was sent successfully, rejected, its id and other errors if they occurred)
Additionally to keep track on every single message you send you can set up SES-SNS to exchange with notifications. It's described in the following article
https://sysgears.com/articles/how-to-track-email-status-with-amazon-ses-and-amazon-sns/
Other problems might occur in your mail client (spam filters etc)
Follow the check list to troubleshoot SES email sending:
Check the SMTP credential is ok or not using code shared by AWS
Same credential using in multiple application/IP may not work
Use minimum mail configuration, if you do not know setting value remove it, do not leave it with NULL.
Set, $config['charset'] = 'UTF-8'; // // 'UTF-8', 'ISO-8859-15'
Set, $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r"
Additional Check
Make sure trying to send email to the same domain if SES account is Sandbox
Check all outbound with mail TCP port is open
If using NATgateway Check both inbound and outbound with mail TCP port is open in open for the mail sending instance in it.

On Mailgun, The Logs show the error: 4.7.1 Received too many messages from a new or untrusted IP

We send a copy of a form that resides on WordPress in Gravity Forms using Mailgun. The account connects and shows the email in the log file on Mailgun.
However, the email is not sent out of Mailgun to the recipient.
The log shows this error on the email: 4.7.1 Received too many messages from a new or untrusted IP
The detail text of the message from the log shows:
delivery-status": {
"tls": true,
"mx-host": "mx1.emailsrvr.com",
"code": 451,
"description": "",
"session-seconds": 0.41779112815856934,
"retry-seconds": 1800,
"attempt-no": 3,
"message": "4.7.1 Received too many messages from a new or untrusted IP: 104.130.122.25 (Z27/3E18C53) (G28)",
"certificate-verified": true
I can find no reference to this on Mailgun or what to do to correct the problem.
Any help much appreciated.

Why amazon emails goes to spam

I have domain with 1&1 and my host is on AWS. I have configured my domain in Route5 and I set MX records. as per below:
10 mydomain.co.uk
10 mx01.1and1.co.uk
10 mx00.1and1.co.uk
The email transfer is working without any problem. The email are stored in 1&1 mail bucket.
I have an application that runs on Cakephp and here is my email Transport configuration.
'EmailTransport' => [
'default' => [
'className' => 'Cake\Mailer\Transport\MailTransport',
/*
* The following keys are used in SMTP transports:
*/
'host' => 'email-smtp.eu-west-1.amazonaws.com',
'port' => 465, // or 587
'timeout' => 30,
'username' => 'info#mydomain.co.uk',
'password' => '*****',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
Now when I send emails the emails are sent to client account but the emails goes in spam. and I get red rock - email not encrypt.
Here is the example of the mail transfer from client account:
from: Company Name Ltd <info#mydomain.co.uk>
to: Alex Manor <alex.manor#gmail.com>
date: Jan 21, 2019, 11:13 PM
subject: You have requested to reset password
security: ec2-11-11-11-11.eu-west-1.compute.amazonaws.com did not encrypt this message Learn more
Thank to #Greg Schmidt.
'default' => [
'className' => 'Cake\Mailer\Transport\SmtpTransport', //<= The class name has to use SMTP
'host' => 'smtp.ionos.co.uk',
'port' => 587,
'timeout' => 30,
'username' => 'info#mydomain.co.uk',
'password' => '*****',
'client' => null,
'tls' => true,
'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
],
After too much reading now I know you wouldn't need to change you host provider for email transport. As long as the email email transport methos is set correctly. you shouldn't get red lock.
Here is a good guide to configure the email DNS transfer
Log into 1and1 and go to Manage domains.
The domain was currently set to use 1&1 name servers with MX records of mx00.1and1.co.uk mx01.1and1.co.uk
Logged into Amazon Route 53.
Created a hosted zone for my domain.
Clicked Created record set then used the MX records from 1and1 i.e., 0 mx00.1and1.co.uk and 1 mx01.1and1.co.uk - This was
the important bit which ensured I didn't lose my inbound email
Went into SES and selected the option to use Route 53 which created my CNAME and TXT records automatically in Route53
As I had the 1and1 MX records set up in Route53 now, I could then go back to 1and1 and change the DNS settings to use other
name servers, then entered my Amazon Route53 name servers instead.
Note: point #6 is good for who wants to use AWS host for email transport.

Can't resend verification code through AWS Cognito API

I have an AWS Cognito User Pool where users are created through Cognito's API using the AdminCreateUser action, which works fine. This sends out a verification e-mail to the user, containing a temporary password. So far so good.
Now a user did not receive this verification e-mail, so I need to send it again, using the ResendConfirmationCode action. I am attempting to do that with the below PHP code.
$userPoolId = '[POOL_ID_HERE]';
$backendAppId = '[APP_ID_HERE]';
$clientSecret = '[SECRET_HERE]';
$username = '[UUID_HERE]';
$secretHash = base64_encode(hash_hmac('sha256', $username . $backendAppId, $clientSecret, true));
$cognitoIdp->resendConfirmationCode([
'ClientId' => $backendAppId,
'SecretHash' => $secretHash,
'Username' => $username,
]);
That gives me the following error:
Aws/CognitoIdentityProvider/Exception/CognitoIdentityProviderException
with message 'Error executing "ResendConfirmationCode" on
"https://cognito-idp.eu-central-1.amazonaws.com"; AWS HTTP error:
Client error: POST https://cognito-idp.eu-central-1.amazonaws.com
resulted in a 400 Bad Request response:
{"__type":"NotAuthorizedException","message":"Can't resend
confirmation code for this user"} NotAuthorizedException (client):
Can't resend confirmation code for this user -
{"__type":"NotAuthorizedException","message":"Can't resend
confirmation code for this user"}'
I am using the credentials of a user which has the following IAM permissions for the user pool:
cognito-idp:AdminDeleteUser
cognito-idp:AdminCreateUser
cognito-idp:AdminAddUserToGroup
cognito-idp:ResendConfirmationCode
If I test the permissions using the IAM Policy Simulator, it gives me the green light, saying that everything is OK. To my knowledge, the cognito-idp:ResendConfirmationCode action should be sufficient, as sending out the verification e-mail works fine when creating the user.
What am I doing wrong here? An alternative approach would be to invoke the AdminCreateUser action again, setting the MessageAction parameter to RESEND. This would force the verification e-mail to be resent for existing users, but I prefer using the ResendConfirmationCode action if I can get it to work.
Any ideas? Thanks!
I understand that you would like your web application end users to receive a confirmation code again if they do not get the confirmation code due to some reason after they sign-up, and I also understand that you are getting the "NotAuthorizedException" when you are trying to run the ResendConfirmationCode API call from your code that uses the PHP SDK.
The ResendConfirmationCode API call[1] can be used after the sign-up API call[2], and it is not a part of the AdminCreateUser Authentication flow, which is why the error is thrown. The AdminCreateUser API call changes the status of the new user to the "Force Change Password State", and neither the ResendConfirmationCode call or the ForgotPassword call can work after AdminCreateUser is used for creating a new user.
If you would like your end-users to get the confirmation code again, you could use the AdminCreateUser API call itself and set the "RESEND" flag in MessageAction in the PHP code. There would be no other way to send the verification message again in this particular use-case, as per my understanding of Amazon Cognito.
An example of the API call in PHP according to the official documentation is as follows[3]:
$result = $client->adminCreateUser([
'DesiredDeliveryMediums' => ['<string>', ...],
'ForceAliasCreation' => true || false,
'MessageAction' => 'RESEND|SUPPRESS',
'TemporaryPassword' => '<string>',
'UserAttributes' => [
[
'Name' => '<string>', // REQUIRED
'Value' => '<string>',
],
// ...
],
'UserPoolId' => '<string>', // REQUIRED
'Username' => '<string>', // REQUIRED
'ValidationData' => [
[
'Name' => '<string>', // REQUIRED
'Value' => '<string>',
],
// ...
],
]);
After using setting 'MessageAction' as 'RESEND', the end-users should be able to receive the verification message again on their end.
References
[1]. https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/resend-confirmation-code.html
[2]. https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/sign-up.html
[3]. https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-cognito-idp-2016-04-18.html#admincreateuser

how to include mail gun API in rails?

I want to use Mailgun in my Rails application.
When I include through Heroku addon it display error to add credit card number though I wanted the free version.
I looked up and found this code from Mailgun. Could someone tell me how to use it?
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:port => 587,
:address => "smtp.mailgun.org",
:user_name => "",
:password => "",
}
end
mail = Mail.deliver do
to 'bar#example.com'
from 'foo#YOUR_DOMAIN_NAME'
subject 'Hello'
text_part do
body 'Testing some Mailgun awesomness'
end
end
I tried using this but it displays an error - mailgun SSL_read: sslv3 alert bad record mac
You need to sign up with Mailgun and get your SMTP username and password which you would use in the mail configuration.