Swift mail and Symfony ([Connection refused #111]) - email

I am getting this error when I try to send an email using the Symfony framework. I had this problem a while back and rember (vaguely), that I had to change my php.ini settings and match them to my /app/config/factories.yml to get it to work.
Unfortunately, I had to rebuild my machine recently, and mail has now stopped working - and unfortunately, I can't remember what I did the last time to get ot to work.
Here is a snippet of the contents of my app/config/factories.yml file:
all:
mailer:
class: sfMailer
param:
logging: %SF_LOGGING_ENABLED%
charset: %SF_CHARSET%
delivery_strategy: realtime
transport:
class: Swift_SmtpTransport
param:
host: localhost
port: 25
encryption: ~
username: ~
password: ~
Note: The indentaion above may be wrong due to being pasted in this console - don't get side tracked by that. The YML is fine on my machine.
This is the logged error message when I try to send an email:
[19-Feb-2011 14:50:13] PHP 20. userActions->executeRegisterComplete() /lib/vendor/symfony/symfony-1.3.8/lib/action/sfActions.class.php:60
[19-Feb-2011 14:50:13] PHP 21. sfMailer->send() /path/to/actions.class.php:355
[19-Feb-2011 14:50:13] PHP 22. Swift_Mailer->send() /lib/vendor/symfony/symfony-1.3.8/lib/mailer/sfMailer.class.php:300
[19-Feb-2011 14:50:13] PHP 23. Swift_Transport_AbstractSmtpTransport->start() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Mailer.php:74
[19-Feb-2011 14:50:13] PHP 24. Swift_Transport_StreamBuffer->initialize() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Transport/AbstractSmtpTransport.php:101
[19-Feb-2011 14:50:13] PHP 25. Swift_Transport_StreamBuffer->_establishSocketConnection() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php:70
[19-Feb-2011 14:50:13] PHP 26. fsockopen() /lib/vendor/symfony/symfony-1.3.8/lib/vendor/swiftmailer/classes/Swift/Transport/StreamBuffer.php:233
[19-Feb-2011 14:50:13] Connection could not be established with host localhost [Connection refused #111]

I've always put like and always have worked;
I simply do not use localhost smtp service.
all:
mailer:
param:
transport:
class: Swift_SmtpTransport
param:
host: smtp.gmail.com
port: 465
encryption: ssl
username: "xxx#gmail.com"
password: xxx-password

The problem could be that you do not have disabled the mail sent in development environment. You have to complete your config_dev.yml like this:
imports:
- { resource: config.yml }
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: true
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
assetic:
use_controller: true
swiftmailer:
disable_delivery: true
You have to set:
disable_delivery: true (not send email)
intercept_redirects: true (if you want to see the email in your debug bar)

I had same error on my hosting provider. I have fixed it by editing factories.yml indentation. Also check your username/password values.

Related

Trying to send email using smtp-relay.gmail.com and Nodemailer. Error ssl3_get_record:wrong version number

Trying to send email with G Suite smtp-relay using Nodemailer.
const transporter = nodemailer.createTransport({
host: "smtp-relay.gmail.com",
port: 587,
secure: true,
auth: {
user: "username#mydomain.com",
pass: "password"
}
});
const result = await transporter.sendMail({
from: `'"JOHN" <john#externaldomain.com>'`,
to: "hello#mydomain.com",
subject: "Hello",
text: "Hello world!",
});
This is what G Suite says about using TLS: Link1 Link2
This is what Nodemailer says: Link
CONTINUE
Basically G Suite tells me that I should use port 587 for TLS, and Nodemailer says I shouldn't.
Don't know if it has something to do with the ports, but this is the error I'm getting:
NOTE: I'm trying on port 587.
{ [Error: 13252:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
] code: 'ESOCKET', command: 'CONN' }
If I change to port 465, I get this error:
'535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8 https://support.google.com/mail/?p=BadCredentials ',
responseCode: 535,
command: 'AUTH PLAIN' }
I know my user and pass are correct.
What am I doing wrong?
Basically G Suite tells me that I should use port 587 for TLS, and Nodemailer says I shouldn't.
Both talk about different things. The first one (G Suite) talks about SSL vs. TLS, i.e. compares various versions of the protocol. The second one (Nodemailer) talks about explicit vs. implicit TLS, i.e. explicitly upgrading a plain connection using the STARTTLS command (port 25 and 587) or establishing TLS directly after the TCP connect (port 465).
Thus, follow the recommendation from Nodemailer to set secure: false. If you want to enforce use of TLS, i.e. fail if STARTTLS is not supported by the mail server, then set requireTLS: true as documented.

Ansible mail module not working with office 365

I am trying to send send an email from ansible
If I try it with gmail it works perfectly, However If I try with office 365 its not working.
Below is my Playbook.
---
- name: Mail Sendig using Ansible
hosts: localhost
tasks:
- name: Mail sending using Mail Module
mail:
host: "smtp.office365.com"
port: 587
username: "dcalert#mycompany.com"
password: "mypasswd"
to: "Jon Snow <jon.snow#mycompany.com>"
subject: "Ansible"
body: "Hello from Ansible"
secure: starttls
I am getting below error
ASK [Send email]
*******************************************************************
An exception occurred during task execution. To see the full
traceback, use -vvv. The error was: SMTPSenderRefused: (501, '5.1.7
Invalid address', 'root')
fatal: [localhost -> localhost]: FAILED! => {"changed": false,
"failed": true, "msg": "Failed to send mail to
jon.snow#mycompany.com: (501, '5.1.7 Invalid address',
'root')", "rc": 1}
You're missing fromparameter...
Take a look here: Ansible Mail Module
It says the parameter from defaults to root. Since you're not setting it, mail server says its invalid. Probably gmail doesnt handle it the same way as office365.
Give this a try...
---
- name: Mail Sendig using Ansible
hosts: localhost
tasks:
- name: Mail sending using Mail Module
mail:
host: "smtp.office365.com"
port: 587
username: "dcalert#mycompany.com"
password: "mypasswd"
from: "dcalert#mycompany.com"
to: "Jon Snow <jon.snow#mycompany.com>"
subject: "Ansible"
body: "Hello from Ansible"
secure: starttls

FOSUserBundle not sending registration email

I have found a few topics related to the same issues, but the solution for them was a miss-configuration of the smtp settings.
I am using symfony 3.0 and latest FOSUserBundle. My config settings are:
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
resetting:
email:
template: email/password_resetting.email.twig
registration:
form:
type: AppBundle\Form\RegistrationType
confirmation:
enabled: true
from_email:
address: registration#site.com
sender_name: 'Our Team'
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
port: "%mailer_port%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I am able to send other emails from the same project, using the same swiftmailer settings.
I have checked the web developer tool and the email is prepared for sending
Web profiler - email area
The registration email is not received in the inbox or spam folders.
Could you let me know if I have missed anything in the configuration files that prevents the registration email from being sent?
Thanks,
Lucia
I found a solution for my problem. The registration email address had to be the same as the one used for the swiftmailer username settings. Having it set to a different email address did not work for me.

Grails mail plugin issues with Gmail SMTP

I'm using the grails mail plugin (2.0.0.RC2) with Grails 3.0.7. This is my config:
mail:
host: smtp.gmail.com
port: 465
username: myuser#gmail.com
password: myPassword
props:
- mail.debug: true
- mail.smtp.auth: true
- mail.smtp.socketFactory.port: 465
- mail.smtp.socketFactory.class: javax.net.ssl.SSLSocketFactory
- mail.smtp.socketFactory.fallback: false
When I try to send a test mail, I get the following error:
Caused by: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at grails.plugins.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:131) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:55) ~[mail-2.0.0.RC2.jar:na]
at grails.plugins.mail.MailService.sendMail(MailService.groovy:59) ~[mail-2.0.0.RC2.jar:na]
at com.eduspace.ClassroomController.$tt__index(ClassroomController.groovy:13) ~[main/:na]
at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.7.jar:3.0.7]
at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.7.jar:3.0.7]
... 9 common frames omitted
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972) ~[javax.mail-1.5.1.jar:1.5.1]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656) ~[javax.mail-1.5.1.jar:1.5.1]
at javax.mail.Service.connect(Service.java:345) ~[javax.mail-api-1.5.1.jar:1.5.1]
... 15 common frames omitted
I see no other debug information in the logs. I have the root logger set to INFO, so everything should be getting outputted. I've verified that I can telnet to smtp.gmail.com port 465, so that's not the issue. I've read that others have had issues with SSL, but then there's usually some debug information indicating an SSL issue and I don't get anything like that.
I am using a slightly different config that works fine:
grails:
mail:
host: "smtp.gmail.com"
port: 465
username: "<username>#gmail.com"
password: "<password>"
props:
mail.smtp.auth: "true"
mail.smtp.socketFactory.port: "465"
mail.smtp.socketFactory.class: "javax.net.ssl.SSLSocketFactory"
mail.smtp.socketFactory.fallback: "false"
The mail config is inside in the grails placeholder and i am not using the dashes as in your example. Maybe this could be of help to you.
This could ofcourse be wrong due to config error but one of the reason for this exact error message is gmail configuration. To avoid spam messages, gmail has started blocking access from apps that do not conform to latest security guidelines.
One easy way to avoid this error is to go to your gmail account and allow less secure apps.- https://www.google.com/settings/security/lesssecureapps
Your configuration looks good.
Here is the mine working fine:
grails {
mail {
host = "smtp.gmail.com"
'default' {
from = "<username>#gmail.com"
}
port = 465
username = "<username>#gmail.com"
password = "<password>"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}

symfony2 + fos user bundle, register confirmation mail not receiving

I installed FOS UserBundle for user login/register. The thing is that after registering, it redirects me on the "../register/check-email" page where it has the well-known message that a mail with the activation link has been sent to the user's email, but I don't receive any e-mail.
My config.yml file has this code for the fos_user:
fos_user:
db_driver: orm
firewall_name: main
user_class: IngrijireMedicalaAcasa\AppBundle\Entity\User
registration:
form:
type: ingrijiremedicalaacasa_appbundle_registration
confirmation:
enabled: true
service:
mailer: fos_user.mailer.default
from_email:
address: noreply#anytext.com
sender_name: any text
Do I have to do any other configuration somewhere?
I mention I tried to change the address "noreply#anytext.com" with my own valid mail address.
I changed even the parameters.yml with my mail details but it still doesn't work.
Oh, and I try to send the mail from my localhost.
I hope you guys know what's the solving to my problem. I think it's a small thing that I don't see, I don't know or I forgot to do it.
try this : (works if your email is gmail (mailer_transport)
#app/config/config.yml
//
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
# host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: IngrijireMedicalaAcasa\AppBundle\Entity\User
registration:
confirmation:
from_email:
address: your.email#gmail.com
sender_name: Any Text
enabled: true
service:
mailer: fos_user.mailer.twig_swift
in your config_dev.yml :
//
assetic:
use_controller: true
swiftmailer:
transport: gmail
username: your.email#gmail.com
password: your password
in app/config/parameter.yml:
//
mailer_transport: gmail
//