1 / 12

Sending Emails with SendGrid and Laravel

Sending Emails with SendGrid and Laravel. Sayed Ahmed Computer Engineering, BUET, Bangladesh (2001) MSc. Computer Science, U of Manitoba, Canada Exploring Computing from 1996. Requirements. A SendGrid Account Cloud based email delivery services http://sendgrid.com/ Beanstalkd

yovela
Télécharger la présentation

Sending Emails with SendGrid and Laravel

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sending Emails with SendGridand 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/master/app/config/queue.php • Basic Mail Configuration for Laravel [Not a Must] • https://github.com/laravel/laravel/blob/master/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 envvars • 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:listenprocess_name=%(program_name)s • numprocs=1 • numprocs_start=0 • autostart=true • autorestart=true • startsecs=1 • startretries=3 • exitcodes=0,2 • stopsignal=TERM • stopwaitsecs=10

  11. Beanstalkd Configuration File Content • user=ubuntu • redirect_stderr=false • stdout_logfile=/var/log/supervisor/qlistener-stdout.log • stdout_logfile_maxbytes=50MB • stdout_logfile_backups=10 • stdout_capture_maxbytes=0 • stdout_events_enabled=false • stderr_logfile=/var/log/supervisor/qlistener-stderr.log • stderr_logfile_maxbytes=50MB • stderr_logfile_backups=10 • stderr_capture_maxbytes=0 • tderr_events_enabled=false environment=LARAVEL_ENV="production" • serverurl=AUTO

  12. Reference • http://b.z19r.com/post/sending-email-with-laravel-sendgrid-beanstalkd-and-go

More Related