AWS SES still uses from #us-west-2.amazonses.com - amazon-web-services

Domain is fully verified but sometimes we did get FROM 0101016efadf82da-b7e07022-37ba-4cae-aa6c-780052992485-000000#us-west-2.amazonses.com instead of using FROM from our domain this is log can you show me what could be possible the reason ?
<< 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-d-XTDLI25GD
>> EHLO [IP]
<< 250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
>> STARTTLS
<< 220 Ready to start TLS
>> EHLO [IP]
<< 250-email-smtp.amazonaws.com
250-8BITMIME
250-SIZE 10485760
250-STARTTLS
250-AUTH PLAIN LOGIN
250 Ok
>> AUTH LOGIN
<< 334 val
>> val
<< 334 val
>> Qk8=
<< 235 Authentication successful.
++ Swift_SmtpTransport started
>> MAIL FROM:<12345#example.com>
<< 250 Ok
>> RCPT TO:<500500500#msg.fi.google.com>
<< 250 Ok
>> DATA
<< 354 End data with <CR><LF>.<CR><LF>
>>
.
<< 250 Ok

First to understand, there are two things in SMTP:
Mailfrom (Envelope From): It's a SMTP command
From header (thats something you see in Outlook)
SES always changes Mailfrom address to message-id#amazonses.com or messageid#us-west-2.amazonses.com (if region used other than us-east-1).
SES does that so you can always pass in SPF. SPF check happens on mailfrom domain which is now us-west-2.amazonses.com and Amazon publishes the TXT/SPF record for it so you don't need to configure it your domain.
AWS SES provides an option to use custom mail from where you can use your own mailfrom but in this case you would need to publish a TXT record so SPF can be passed.
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/mail-from.html
Generally, you don't see Mailfrom in outlook or any webmail. The reason you're seeing it because in your telnet test, you're not adding from header. Try below test: (Add DATA command after "rcpt to" and add below line)
>> MAIL FROM:<12345#example.com>
<< 250 Ok
>> RCPT TO:<500500500#msg.fi.google.com>
Data
From: 12345#example.com
To: 500500500#msg.fi.google.com
Subject: Test
.
Once you add the From header, you should be able to see correct address in outlook or webmail.

Related

Different server/IP - no more connection?

I'm using Mailgun through my local installation of Mautic. It used to connect correctly. Today however I got this error message: Unable to connect with TLS encryption Log data: ++ Starting Swift_SmtpTransport << 220-node6237.myfcloud.com ESMTP Exim 4.95 #2 Tue, 12 Apr 2022 13:38:14 +0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. >> EHLO dashboard.nsking.ee << 250-node6237.myfcloud.com Hello dashboard.nsking.ee [194.233.160.33] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-PIPE_CONNECT 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP >> STARTTLS << 220 TLS go ahead !! Unable to connect with TLS encryption (code: 0) ++ Starting Swift_SmtpTransport << 220-node6237.myfcloud.com ESMTP Exim 4.95 #2 Tue, 12 Apr 2022 13:38:14 +0000 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. >> EHLO dashboard.nsking.ee << 250-node6237.myfcloud.com Hello dashboard.nsking.ee [194.233.160.33] 250-SIZE 52428800 250-8BITMIME 250-PIPELINING 250-PIPE_CONNECT 250-AUTH PLAIN LOGIN 250-STARTTLS 250 HELP >> STARTTLS << 220 TLS go ahead !! Unable to connect with TLS encryption (code: 0)
What is the cause of it? Keep in mind, nothing has changed in our installation except the server name and the IP.
I tried to change to SSL and I got this error:
Connection could not be established with host smtp.mailgun.org :stream_socket_client(): Peer certificate CN=node6237.myfcloud.com' did not match expected CN=smtp.mailgun.org' Log data: ++ Starting Swift_SmtpTransport !! Connection could not be established with host smtp.mailgun.org :stream_socket_client(): Peer certificate CN=node6237.myfcloud.com' did not match expected CN=smtp.mailgun.org' (code: 0)
++ Starting Swift_SmtpTransport !! Connection could not be established with host smtp.mailgun.org :stream_socket_client(): Peer certificate CN=node6237.myfcloud.com' did not match expected CN=smtp.mailgun.org' (code: 0)

Smtp client hangs after sending data

I want to build an stmp client using c++ for learning purposes.
After I managed to implement the initial connection + auth login I am stuck on sending the message after using the data command.
Here is my code
void sendmail()
{
write_command("MAIL FROM: <foo#bar.de>");
write_command("RCPT TO: <bar.foo#baz.de>");
write_command("DATA");
write_command("Subject: testmail"); // HANGS here after data command
write_command("BlaBlub");
write_command(" ");
write_command(".");
write_command("QUIT");
}
void write_command(std::string command)
{
ssize_t n;
empty_buffer();
command += '\r';
command += '\n';
char command_buffer[255];
strcpy(command_buffer, command.c_str());
n = write(sockfd,command_buffer,strlen(command_buffer));
if (n < 0){
error("ERROR writing to socket");
}
n = read_to_buffer();
if (n < 0) {
error("ERROR reading from socket");
}
printf("%s\n",this->buffer);
}
I'm using smtp.mailtrap.io on port 25.
Here is a gist with the full class https://gist.github.com/xhallix/7f2d87a8b2eab4953d161059c2482b37
Here is the server output
Starting smpt client
220 mailtrap.io ESMTP ready
250-mailtrap.io
250-SIZE 5242880
250-PIPELINING
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-AUTH PLAIN LOGIN CRAM-MD5
250 STARTTLS
334 VXNlcm5hbWU6
334 UGFzc3dvcmQ6
235 2.0.0 OK
250 2.1.0 Ok
250 2.1.0 Ok
354 Go ahead
(HANGS HERE)
Thanks for helping me out
DATA command expects the whole mail message, as shown here. The write_command() sends a message by lines and expects response after each line. Since the server returns the response once the mail message is finished (after empty line and dot), it stays in the hanging mode after the first message line. This code snippet can be helpful for your case.
BTW, you should put an empty line between the mail header and body, which I guess is after the subject line. Also, it might happen that the server rejects the message without the From and To headers.

ASP.NET Core + Amazon SES: The remote certificate is invalid according to the validation procedure

I am trying to send email using ASP.NET Core, MailKit and Amazon SES:
using (SmtpClient client = new SmtpClient(new ProtocolLogger("smtp.log"))) {
client.Connect("email-smtp.us-east-1.amazonaws.com", 587, SecureSocketOptions.StartTls);
client.Authenticate("myusername", "mypassword");
await client.SendAsync(message);
client.Disconnect(true);
}
I keep getting the error "The remote certificate is invalid according to the validation procedure.".
And the log file shows:
Connected to smtp://email-smtp.us-east-1.amazonaws.com:587/?starttls=always
S: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-1737464811 qt5bXhIgVseJaHPspjp4
C: EHLO [127.0.0.1]
S: 250-email-smtp.amazonaws.com
S: 250-8BITMIME
S: 250-SIZE 10485760
S: 250-STARTTLS
S: 250-AUTH PLAIN LOGIN
S: 250 Ok
C: STARTTLS
S: 220 Ready to start TLS
What am I missing?
You need to provide your own client.ServerCertificateValidationCallback method to verify the server certificate. It can be as simple as always returning true or it can check the fingerprint against a known fingerprint for the server or any number of other possibilities.
For more information, see http://www.mimekit.org/docs/html/P_MailKit_MailService_ServerCertificateValidationCallback.htm

unable to send mail through php mail() function getting exception - Must issue a STARTTLS command first

Even after two days of continuous trials.. I am stuck with "mail sending failed" error
Although many solutions are there on stack overflow itself but I am still asking this becoz none of them helped
Pre--(if required)
Using WINDOWS 10 ,php 5.5.12 ,apache 2.4.9
My approach
1) downloaded smtp
2) configured smtp.ini
3) configured php.ini
4) configured my gmail account
Note
I have tried all possible approaches and more than 15 tutorials till now to get this mail thing done in last 2 days...
but :(
also I have set my gmail account to allow less secure apps , enabled IMAP and disbled 2 step verification
I am enclosing the error log files and my smtp and php.ini files
configuration for fake sendmail
; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=587
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=none
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify
default_domain=localhost
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=myid#gmail.com
auth_password=mypasswordhere
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required.
pop3_server=
pop3_username=
pop3_password=
; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content
force_sender=myid#gmail.com
; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify
; the "To: " header of the message content
force_recipient=
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
hostname=localhost
I am getting the following error log
16/03/19 09:44:36 ** --- MESSAGE BEGIN ---
16/03/19 09:44:36 ** To: somenath#gmail.com
16/03/19 09:44:36 ** Subject: Testing sendmail.exe
16/03/19 09:44:36 ** X-PHP-Originating-Script: 0:tt1.php
16/03/19 09:44:36 ** From: myid#gmail.com
16/03/19 09:44:36 ** MIME-Version: 1.0
16/03/19 09:44:36 ** Content-type: text/html; charset=utf-8
16/03/19 09:44:36 **
16/03/19 09:44:36 ** Hi, you just received an email using sendmail!
16/03/19 09:44:36 ** --- MESSAGE END ---
16/03/19 09:44:36 ** Connecting to smtp.gmail.com:587
16/03/19 09:44:36 ** Connected.
16/03/19 09:44:37 << 220 smtp.gmail.com ESMTP wx3sm24328300pab.25 - gsmtp<EOL>
16/03/19 09:44:37 >> EHLO localhost<EOL>
16/03/19 09:44:37 << 250-smtp.gmail.com at your service, [115.248.50.20]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250-PIPELINING<EOL>250-CHUNKING<EOL>250 SMTPUTF8<EOL>
16/03/19 09:44:37 ** Authenticating as myid#gmail.com
16/03/19 09:44:37 >> MAIL FROM: <myid#gmail.com><EOL>
16/03/19 09:44:37 << 530 5.7.0 Must issue a STARTTLS command first. wx3sm24328300pab.25 - gsmtp<EOL>
16/03/19 09:44:37 ** Disconnecting from smtp.gmail.com:587
16/03/19 09:44:37 ** Disconnected.
16/03/19 09:44:37 ** Disconnected.
16/03/19 09:44:37 ** Must issue a STARTTLS command first. wx3sm24328300pab.25 - gsmtp<EOL>
here is the snippet of php.ini
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = myid.1994#gmail.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on NT, not valid in Windows 95).
;mail.log = syslog
4) my php code
<?php
$to = 'somenath#gmail.com';
$subject = 'Testing sendmail.exe';
$message = 'Hi, you just received an email using sendmail!';
$headers = 'From: myid#gmail.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=utf-8';
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
?>
In your config:
smtp_ssl=none
You're turning off the very thing that you need. You're using port 587 (as you should), so you need to set smtp_ssl=auto or smtp_ssl=tls.
This comment in the PHP docs shows how to set user id and password properties.
Finally got it working
For those fellows who have almost given up ,just like I had, after 48 hours of tries :(
Here is something which you should cherish
do everything as I have posted above in my question
ie
1) download smtp
2) configure smtp.ini
3) configure php.ini
4) configure your gmail account
5) also set your gmail account to allow less secure apps , enable IMAP and disble 2 step verification
make sure you do these
--smtp_ssl=none
to
smtp_ssl=ssl
and
smtp_port=587
to
smtp_port=465
Now Most important thing that was the problem in my case
I had not configured my sendmail.exe...
so
DO this
1) go to sendmail folder where you have your sendmail.exe
2)right click on sendmail.exe -->then properties
3)go compatibilty tab
4) change compatability for all users
5) tick run as admin
6) and most importantly, under compatibilty mode select windows service pack 3
7) apply and done
hope it helps
comment if you face any problem :)

using wsock32 to send email with gmail and startTLS

Hello and good evening to you,
This topic has been sort of a trouble to me and to many, suppose i want to send EMail in a C++ program to use smtp and StartTLS , what do i do, i culled a simple source code from google and i saw this code from here
http://www.drdobbs.com/sending-e-mail-using-smtp-and-winsock/184416591
now i want to use google mail and it uses authentication for smtp and also startTLS how do i do this
the sourcecode i saw looks like this
#pragma comment(lib, "wsock32.lib")
#include <windows.h>
#include "MailMessage.h"
int main(int argc, char **argv)
{
MailMessage mail("A Sender",
"someone#someplace.com",
"mail.someplace.com");
mail.To("A Recipient",
"you#yourplace.com");
mail.Subject("Sample message");
mail.Body("Plain text body",
"<HTML><BODY>\r\n"
" <H2>HTML Body</H2>\r\n"
"</BODY></HTML>""\r\n");
mail.Attach("C:\\Attach.txt");
const char *result =
mail.Send().data();
if (result[0] == '\0')
result = "Success";
MessageBox(NULL, result, "Result",
MB_ICONINFORMATION|MB_OK);
return 0;
}
After connecting to the server and issuing a EHLO (not HELO) command, if the server's reply includes the STARTTLS capability then you can issue a STARTTLS command at any time to create a secure session with the server. Upon receiving a successful STARTTLS reply, you need to send and complete an SSL/TLS handshake. Once the session has been created, you can continue sending your SMTP commands and receiving SMTP replies, starting with a new EHLO command (as the server's capabilities can change after the connection is secured). You have to encrypt your commands and decrypt the replies as you go. The communication would look like this (this example assumes an Application-Specific password has been configured in GMail if two-step verification is enabled):
S: 220 smtp.gmail.com ESMTP dg12sm55710335pac.47 - gsmtp
C: EHLO <hostname>
S: 250-smtp.gmail.com at your service, [<ip address>]
S: 250-SIZE 35882577
S: 250-8BITMIME
S: 250-STARTTLS
S: 250-ENHANCEDSTATUSCODES
S: 250-PIPELINING
S: 250-CHUNKING
S: 250 SMTPUTF8
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
C/S: (Exchange SSL/TLS handshake)
C/S: (Everything from here on is now encrypted)
C: EHLO <hostname>
S: 250-smtp.gmail.com at your service, [<ip address>]
S: 250-SIZE 35882577
S: 250-8BITMIME
S: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
S: 250-ENHANCEDSTATUSCODES
S: 250-PIPELINING
S: 250-CHUNKING
S: 250 SMTPUTF8
C: AUTH LOGIN
S: 334 VXNlcm5hbWU6
C: (Send base64 encoded username)
S: 334 UGFzc3dvcmQ6
C: (Send base64 encoded password)
S: 235 2.7.0 Accepted
C: (Send email as needed)
C: QUIT
S: 221 2.0.0 closing connection m1sm91929700pfi.27 - gsmtp
Now, how you actually handle the encryption is up to you. You can use a library like OpenSSL, or you can use Microsoft's Crypto/SChannel API. There are plenty of online tutorials and books on how to use them with sockets.