<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akeem Amusat</title>
    <description>The latest articles on DEV Community by Akeem Amusat (@aoamusat).</description>
    <link>https://dev.to/aoamusat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F33524%2F95c17209-2843-4a25-9a45-6d51fa707864.jpg</url>
      <title>DEV Community: Akeem Amusat</title>
      <link>https://dev.to/aoamusat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aoamusat"/>
    <language>en</language>
    <item>
      <title>Sending Email in Laravel App Using Gmail Account</title>
      <dc:creator>Akeem Amusat</dc:creator>
      <pubDate>Tue, 31 Aug 2021 09:41:57 +0000</pubDate>
      <link>https://dev.to/aoamusat/sending-email-in-laravel-app-using-gmail-account-iaj</link>
      <guid>https://dev.to/aoamusat/sending-email-in-laravel-app-using-gmail-account-iaj</guid>
      <description>&lt;p&gt;Laravel framework made sending email very easy for developers using the &lt;code&gt;Mailable&lt;/code&gt; class. I will be using an existing Laravel 8 application. You can also follow the tutorial using other Laravel versions (6 or 7). Follow the steps below to configure your Laravel app for sending mail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step one: generate app password on Google account
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://support.google.com/accounts/bin/answer/185833?hl=en" rel="noopener noreferrer"&gt;App password&lt;/a&gt; is required by your application to access Gmail account via SMTP or other protocol. To create the app password:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Login into your &lt;a href="https://myaccount.google.com/" rel="noopener noreferrer"&gt;Google account&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Click on the security tab
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftb4xxhzz9uzce3xdy8qd.png" alt="image"&gt;
&lt;/li&gt;
&lt;li&gt;Enable 2FA&lt;/li&gt;
&lt;li&gt;Click on App passwords
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flboltsr90evupctlx9pg.png" alt="image"&gt;
Select &lt;strong&gt;Mail&lt;/strong&gt; in the app select dropdown. For device, select others and give it the name you want.&lt;/li&gt;
&lt;li&gt;Click on generate
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgj1jpqdluo86fpywnh5c.png" alt="image"&gt;
Copy the generated app password. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step two: update your application &lt;code&gt;.env&lt;/code&gt;
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

MAIL_DRIVER=smtp
MAIL_FROM_ADDRESS=user@gmail.com
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=user@gmail.com
MAIL_PASSWORD=App Password
MAIL_ENCRYPTION=tls


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Step three: send the email using the Laravel built-in &lt;code&gt;Mail&lt;/code&gt; facade.
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;

&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Routing\Route&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Support\Facades\Mail&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/sendmail'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$ip&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nc"&gt;Mail&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hi user, a new login into your account from the IP Address: '&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nv"&gt;$ip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'MAIL_FROM_ADDRESS'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'MAIL_FROM_NAME'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'user@domain.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'User Name'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can read more about sending mail, adding attachments, sending mail using Laravel blade templates: visit the &lt;a href="https://laravel.com/docs/8.x/mail" rel="noopener noreferrer"&gt;Laravel Mail&lt;/a&gt; documentation for more details.&lt;br&gt;
Follow me for more of my articles, you can leave comments, suggestions, and reactions. &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>fullstack</category>
    </item>
  </channel>
</rss>
