Answer the question
In order to leave comments, you need to log in
How to properly send messages via swiftmailer Symfony2-3?
Good day to all! Faced a new task: sending messages via symfony2-3:
problem with authenticate on the gmail side.
What I have in stock:
//app/config/config.yml
//настройки swiftmailer для отправки сообщения на почту:
swiftmailer:
transport: stmt
username: [email protected]
password: password
host: smtp.gmail.com
port: 465
encryption: ssl
auth_mode: login
Step 1: Make Sure You Need POP
You can use IMAP or POP to work with Gmail in third-party clients.
Using the IMAP protocol, you can work with Gmail mail on several devices at once. Letters in this case are synchronized in real time.
POP access can only be enabled on one computer. In this case, letters will not be synchronized in real time - they will be downloaded to the client at the frequency that you specify.
Step 2: Set up POP access Set
up POP in Gmail first
Open Gmail on your computer.
In the upper right corner, click on the Settings icon.
Click Settings.
Click the Forwarding and POP/IMAP tab.
In the "POP Access" section, select Enable POP for all emails or Enable POP for emails received since now.
Click Save Changes at the bottom of the page.
Then configure your mail client
Open a client (for example, Microsoft Outlook) and set the following parameters:
Incoming mail server (POP)
pop.gmail.com
SSL required: yes
Port: 995
Outgoing mail server (SMTP)
smtp.gmail.com
SSL required: Yes
TLS Required: Yes (if available)
Authentication Required: Yes
SSL Port: 465
TLS/STARTTLS Port: 587
If you use Gmail at your organization or school, enter mail.domain.com and select port 110.
Server timeout More than 1 minute (5 minutes recommended)
Full name or display name Your name
Account, username or email address Your email address
Password Your Gmail password
- symphony parameter ("gearbox" (relay) by ports) - transport: smtp
- Outgoing mail server (SMTP) - host: smtp.gmail.com
- Requires SSL: yes - encryption: ssl
- Authentication required: yes - auth_mode: login
- Port for SSL: 465 - port: 465
- Account, username or email - username: [email protected]
- Your Gmail password - password: password
swiftmailer: transport: stmt username: [email protected] password: password host: smtp.gmail.com port: 465 encryption: ssl auth_mode: login
class SendMailController extend Controller
{
//до сюды даже не доходит
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody(
$this->renderView(
'AppJoboardBundle:Affiliate:email.txt.twig',
array('name' => 'mailer')
)
)
;
$this->get('mailer')->send($message);
}
Failed to authenticate on SMTP server with username "[email protected]" using 1 possible authenticators
Answer the question
In order to leave comments, you need to log in
After a short search, I found a solution:
In principle, everything was done correctly, with the exception of one nuance.
I will describe a detailed description of how I did everything, maybe it will help someone, although everything is in the docks: well, or almost everything ... "he-he-he" ....
the first thing I did was add parameters for swiftmailer:
//app/config/config.yml
...
# Swiftmailer Configuration
swiftmailer:
transport: smtp
username: "%mailer_user%"
password: "%mailer_password%"
host: "%mailer_host%"
port: "%mailer_port%"
encryption: "%mailer_encryption%"
auth_mode: "%mailer_auth_mode%"
//app/config/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "@AppJoboardBundle/Resources/config/parameter_mailer.yml" }
parameters:
mailer_user: [email protected]
mailer_password: password
mailer_host: smtp.gmail.com
mailer_port: 465
mailer_encryption: ssl
mailer_auth_mode: login
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody(
$this->renderView(
'AppJoboardBundle:Affiliate:email.txt.twig',
array('name' => 'mailer')
)
)
;
$this->get('mailer')->send($message);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question