I trying to send an email though amazon AWS
I have confirmed that I am able to send a email through postie like this:
postie.exe -host:email-smtp.eu-west-1.amazonaws.com -port:587 -ssl -tls -esmtp -to:barn.fleischer#gmail.com -from:barn.fleischer#gmail.com -s:"testmail" -msg:"This is a test" -user:XXXX -pass:YYYY
But when I try to send via System.Net.Mail
<mailSettings>
<smtp from="barn.fleischer#gmail.com">
<network host="email-smtp.eu-west-1.amazonaws.com"
port="587"
userName="XXXX"
password="YYYY"
enableSsl="true"/>
</smtp>
</mailSettings>
Unhandled Exception: System.Net.Mail.SmtpException: Failure sending mail.
---> System.Net.WebException: Unable to connect to the remote server
---> System.Net.Sockets.SocketException:
No connection could be made because the target machine actively refused it
Any suggestions?
Erik
Have you checked outgoing Windows firewall settings on that server? Make sure you have opened all standard ports eg 25 465 587 etc.
Related
I am trying to setup a email server on Google clou for which I have used iRedMail. I have followed this link to setup. There was no error in logs while sending email to this email server but when I try to send from the UI to my email ID it is giving me following error in logs. ( /var/log/mail.log ).
Dec 8 10:19:36 comm postfix/smtp[4142]: connect to mail.tinydef.com[157.230.67.25]:25: Connection timed out
Dec 8 10:19:36 comm postfix/smtp[4142]: 4J8CnP4ND5z3ygl: to=<jamir46881#tinydef.com>, relay=none, delay=31, delays=0.02/0.03/31/0, dsn=4.4.1, status=deferred (connect to mail.tinydef.com[157.230.67.25]:25: Connection timed out)
I am aware that port 25 is blocked on GCP. Just trying to figure a way out from this situation. Is there any configuration that can be tweaked to change port 25 to some other port ?
You cannot send mail to external IP addresses on port 25 from instances in Google Cloud. There is no appeal process to change this policy.
Sending email from an instance
To function as a mail server requires communication between servers on port 25. Mail relays can use any port the mail server supports except for port 25.
iRedMail can function as a traditional mail server, which requires port 25, and as a mail relay to forward mail to a mail server.
Setup relayhost
Your solution is to configure iRedMail as a relay host forwarding mail on port 465 or 587 to a mail service such as Gmail, Office 365, SendGrid, etc. The email service will deliver your email.
So I have a domain purchased through SES which I have verified with SES.I have tested that sending/receiving works by signing into the email with the workmail web app.I am getting the following error when trying to send email with my spring app.
javax.mail.MessagingException: Could not connect to SMTP host: email-smtp.eu-west-1.amazonaws.com, port: 25, response: 421
Appconfig.Java
#Configuration
#PropertySource("app.properties")
#EnableTransactionManagement
public class AppConfig {
#Autowired
private Environment env;
#Bean
public JavaMailSender getJavaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("email-smtp.eu-west-1.amazonaws.com");
mailSender.setPort(25);
mailSender.setUsername("noreply#mydomain.com");
mailSender.setPassword("mypassword");
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.debug", "true");
return mailSender;
}}
EmailServiceImpl.java
#Component
public class EmailServiceImpl {
#Autowired
public JavaMailSender emailSender;
public void sendSimpleMessage(String toAddress, String subject, String text)
{
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(toAddress);
message.setSubject(subject);
message.setText(text);
emailSender.send(message);
}
}
EmailServiceImpl is autowired into my web controller where I send an email after generating a password reset token
First of all,you have done everything right as said in the AWS docs.
You are right in using your smtp credentials as you are using their smtp interface to send mail,and not their aws sdk(if you use,aws sdk,you have to use acces key and password).
But,here comes some other issues which might help you resolve the issues which we have to do as it is not there in the docs.
You have to troubleshoot the error code sent by smtp.
Mostly,SMTP error code 421 shows up when the recipient mail server is very busy as it is receiving a lot of messages,so it temporarily defers your message by giving this error code or your recipient client have some problems.
You can study here.
https://sendgrid.com/blog/smtp-server-response-codes-explained/#:~:text=421%20%E2%80%93%20Your%20message%20was%20temporarily,locked%20or%20is%20not%20routable.
https://www.arclab.com/en/kb/email/smtp-response-codes-error-messages.html#:~:text=The%20SMTP%20error%20421%20is,see%20SMTP%20Error%20451%20below).
You can try sending the mail after sometime or you can try sending with different port.
My Incident:
I was using AWS SES for sending mail from my Springboot Application.
I was also using SMTP interface of AWS ses like you.
There are 3 ports which are listed on AWS management console to send mail.
But,when I was using Port 465,it was not working.
But,when I was using Port 25 or Port 587,it was working.
But,even then,It is always recommended to use 587 as it is recommended by IETF and is safest to use with TLS.
Using Port 465 is least recommended.You can study here but AWS supports it.There are many clients still supporting it but it is not widely in use.
As,I told you in my case it was failing.
You can study here about all the 3 ports and how port 465 functioning is different from port 25 and 587
But,you can solve the issue of port 465 by using smtps protocol with it.
Port-25,587(use smtp as protocol)
Port-465(use smtps as protocol,as in this case client has to initiate the tls encryption)
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html
You can get a guide from where to chose a port.
https://pepipost.com/blog/25-465-587-2525-choose-the-right-smtp-port/
You are using port 25. SES uses port 465 or 2465. Also remember to use SES SMTP credentials and not your IAM credentials (AccessKey).
Connecting to the Amazon SES SMTP Endpoint
I am trying to connect to Gmail through CFIMAP and I am getting a connection timed out error. This code works on my dev environment but not on production. I have also opened a ticket with my ISP just in case.
This is the error
An exception occurred when setting up mail server parameters.
This exception was caused by: javax.mail.MessagingException: Connection timed out: connect; nested exception is: java.net.ConnectException: Connection timed out: connect.
And this is my code:
<cfimap
server = "imap.gmail.com"
username = "surveysemail#signatureforum.com"
action="open"
password = "test"
connection = "mail.test.com"
timeout = 120>
I had the secure parameter in before and also the port but I removed them while testing different options. Also, I just added the timeout parameter but did not work either.
GMail is particular as to the types of connection it receives. Generally this chalks up to a security issue because the server you're trying to log into Gmail from (at your ISP) is in a different location and has never logged in from the browser on that machine.
There's a couple of things you can do here:
First, If you have RDP access to the server at your ISP, you can log in to Gmail from the server, then try again.
If that doesn't work, review the "Device activity and notifications" page on the Gmail account to see if Google is blocking access from the server. (https://myaccount.google.com/security?hl=en&pli=1#activity)
Give that a shot... most likely Gmail is seeing the activity coming from your server as erroneous and is blocking it from that front.
We have had issues with our server being used to send spam via cfmail to our remote SMTP server. I cannot see where it is occurring, but the emails are sent from a domain that is not one on our server.
Is there a way using ColdFusion administrator to specify that only emails showing as from someone#mydomain.com are sent to the SMTP host via the spool?
Thanks in advance,
Paul
It sounds to me like the <cfmail> side of things here is a red herring and you have got an open relay on your mail server. You seriously need to disable that immediately! If your SMTP server has to relay email for your CFML app then make sure it's not configured to relay everything, instead just for the IP address of the CF server, or for the credentials the CF server uses to connect to it.
If you don't know how to configure the relaying settings for your SMTP server, raise another question on serverfault.com asking how. Provide the exact details of your SMTP server, as well as the requirement to still allow relaying for the CF server.
I am trying to connect to an amazon server for sending emails by editing by web.config
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network enableSsl="true" port="587" host="email-smtp.us-east-1.amazonaws.com" password="actual password" userName="actual username"/>
</smtp>
</mailSettings>
</system.net>
These settings are being set as evidenced below:
All I am doing in code is
SmtpClient client = new SmtpClient();
client.SendCompleted += SendCompletedCallback;
string userState = _id.ToString();
client.SendAsync(msg, userState);
but the error I get back is always
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 184.73.222.29:587
Before I was using an internal mail server, but since this will be getting pushed to the amazon cloud, I will not have access to the local server. In the case of the local server, all i had to do was specify the ip address for host and it ran just fine.
There were three issues at hand:
1: The email address it was being sent from was not verified with Amazon, and neither was the recipient (verification of recipient only needed in sandbox mode)
2: The out port I was using, 587, is blocked by my company, which seems to be common practice
3: Using async can only be done when you specify the page uses async in the aspx "header"