ICT role in 21st century education and its challenges
Sending email with send grid and laravel
1. Sending Emails with SendGrid and
Laravel
Sayed Ahmed
Computer Engineering, BUET, Bangladesh (2001)
MSc. Computer Science, U of Manitoba, Canada
Exploring Computing from 1996
2. Requirements
A SendGrid Account
◦ Cloud based email delivery services
◦ http://sendgrid.com/
Beanstalkd
◦ Email queue
◦ http://kr.github.io/beanstalkd/
Laravel go mail worker
◦ Laravel Mail sender using Sendgrid [as an example]
◦ https://github.com/zackkitzmiller/laravel-go-mail-
worker
◦ https://github.com/zackkitzmiller/laravel-go-mail-
worker/blob/master/laravel-go-mail-
worker/app/commands/QueueEmailCommand.php
◦ https://github.com/zackkitzmiller/laravel-go-mail-
worker/blob/master/go/src/zackkitzmiller/laravel-go-mail-worker/main.go
3. Must Watch
Mail Queue configuration for Laravel
◦ https://github.com/laravel/laravel/blob/mas
ter/app/config/queue.php
Basic Mail Configuration for Laravel
[Not a Must]
◦ https://github.com/laravel/laravel/blob/mas
ter/app/config/mail.php
4. How These All Will Work
You need to queue the message in Beanstalkd
◦ You need to configure Laravel and Laravel Go Mailer for
that
◦ From your code, you need to use methods to queue the
message
$message = "This is a queue test job. We won't really need to pass
data for this demo.";
Queue::push('QueueDemo', array('message' => $message));
◦ This apparently looks like will also work
Mail::queueOn('queue-name', 'emails.welcome', $data,
function($message) { $message
->to('foo@example.com', 'John Smith')
->subject('Welcome!'); });
◦ Then the GO application will send this email
It’s Laravel go mail worker
◦ Then Go mailer will use SendGrid to send the mail
5. How These All Will Work
Configuration for Go mail worker
◦ BEANSTALKD: location of the beanstalk
installation (e.g. localhost:11300)
◦ SENDGRID_USER: username for
sendgrid account
◦ SENDGRID_PASS: password for
sendgrid account
6. Installation
Install Go Mailer
◦ Artisan command email:send. Will do that
for you
Not sure yet that it will work; after working with
it, I will update
◦ Though you can get the copy of the
Laravel-go-mailer and use that for sure
7. Miscellaneous
How to Download and Install Beanstalkd
◦ http://kr.github.io/beanstalkd/download.html
◦ Src: git clone git://github.com/kr/beanstalkd.git
◦ Install:
Mac: sudo port install beanstalkd
Debian: sudo apt-get install beanstalkd
Ubuntu: sudo apt-get install beanstalkd
Fedora: su -c 'yum install beanstalkd'
Sending emails from Laravel using Mail
Servers such as SwiftMailer
◦ http://laravel.com/docs/mail
Mail Queue tutorial for Laravel
◦ http://vimeo.com/64779946
8. Miscellaneous
Beanstalkd listed as the default in
Laravel-go-mailer queue config file
◦ https://github.com/zackkitzmiller/laravel-
go-mail-worker/blob/master/laravel-go-
mail-worker/app/config/queue.php
These are the environment variables
◦ Set SENDGRID_USER,
SENDGRID_PASS, and BEANSTALKD
env vars
◦ Can be set in Linux profile type files
Also from within PHP you can set
9. Environment Variables and
PHP
echo 'My username is ' .$_ENV["USER"] . '!'
;
// Example use of getenv()
$ip = getenv('REMOTE_ADDR');
putenv("UNIQID=$uniqid");
10. Beanstalkd Configuration File
Content
You can know but you will not need to work with
it much for basic functionality
◦ [program:qlistener]
◦ command=php /var/www/laravel/artisan queue:listen
process_name=%(program_name)s
◦ numprocs=1
◦ numprocs_start=0
◦ autostart=true
◦ autorestart=true
◦ startsecs=1
◦ startretries=3
◦ exitcodes=0,2
◦ stopsignal=TERM
◦ stopwaitsecs=10