Ruby Programming
Attraction Mailbox - Why I love Action Mailbox

Summarized using AI

Attraction Mailbox - Why I love Action Mailbox

Cody Norman • October 07, 2024 • Boulder, CO

In the presentation titled "Attraction Mailbox - Why I Love Action Mailbox," Cody Norman, an independent Ruby consultant, discusses the capabilities of Action Mailbox in Ruby on Rails applications. The talk highlights how email is an effective and low-friction interface for user interactions, presenting Action Mailbox as a solution for handling inbound emails effortlessly. Key points of the presentation include:

  • Introduction to Action Mailbox:

    • Action Mailbox routes inbound emails to controller-like mailboxes for processing, creating an inbound email record that can be processed in the background using Active Job.
  • Use Cases for Action Mailbox:

    • Parsing PDF attachments from emails to create models seamlessly.
    • Implementing an email-to-SMS service, allowing users to send texts via emails.
    • Creating AI applications by processing email content and interacting with APIs like OpenAI.
  • Practical Examples:

    • Norman demonstrates a live production app with features like sending transaction emails based on inbound messages without requiring user interaction.
  • Inbound Email Processing Flow:

    • Inbound emails are processed via webhooks received from email service providers.
    • The application authenticates the request and processes the email efficiently, leveraging familiar Rails tools.
  • Deployment Considerations:

    • Tips on deploying Action Mailbox in production, emphasizing URL options for Active Storage, and finding efficient email routing methods.
  • Impractical Examples:

    • Norman shares humorous examples to inspire thinking outside the box, such as a "catfax on demand" feature and a mailbox integration that sends reminders as physical postcards.
    • Also mentioned is a customizable truck-starting service that responds to specific inbound emails to engage in unnecessary but fun functionalities.

In conclusion, Cody emphasizes the flexibility and ease of usage with Action Mailbox, making it possible for applications to meet user needs without traditional constraints like account verification. The session wraps up by encouraging developers to experiment with Action Mailbox's capabilities as a tool to enhance user experience. Norman provides links for follow-up and email options for accessing the presentation slides.

This talk was presented at the Rocky Mountain Ruby 2024 conference, appreciating the blend of Ruby and local engagement while also acknowledging the diverse audience present.

Overall, the key takeaway from this session is that Action Mailbox simplifies the handling of inbound emails in Rails applications, allowing for innovative integrations and user interactions without needing users to log in or navigate the application interface directly.

Attraction Mailbox - Why I love Action Mailbox
Cody Norman • October 07, 2024 • Boulder, CO

Email is a powerful and flexible way to extend the capabilities of your Rails application. It’s a familiar and low friction way for users to interact with your app.

As much as you may want your users to access your app, they may not need to. Email is a great example of focusing on the problem at hand instead of an over-complicated solution.

We’ll take a deeper look at Action Mailbox and how to route and process your inbound emails.

Rocky Mountain Ruby 2024

00:00:13.559 how's everyone hanging in there I know it's I know it's day two so is everyone everyone's still feeling
00:00:19.519 okay uh you all are aware that you're in a talk about inbound emails too
00:00:24.720 everyone's in the right place okay just check so first off um just like to say
00:00:30.679 thank you to uh the organizers and all the volunteers for for putting this on um I live here in Colorado uh not
00:00:38.120 necessarily local but this is about as local as it gets for me so combining Colorado and Ruby uh are are really two
00:00:45.559 of my favorite things and bringing people in and being able to share that uh is something I'm very thankful for so
00:00:52.440 thank you for having me out to speak and thank you to all of you for making it I know people are uh different countries
00:00:58.680 different states um some people's first conference so um yeah thank you for making it out and thank you for sitting
00:01:05.760 here listening to uh some inbound email parsing thought so a little bit about me uh my
00:01:13.280 name is Cody Norman uh I'm an independent Ruby consultant uh and I live in a small mountain town here in
00:01:19.520 Colorado uh called Bailey so another thing about
00:01:25.840 me I really love email and and I know this Probably
00:01:31.159 sounds a little bit odd but email is such a powerful and flexible tool for
00:01:36.720 users to be able to interact with your application in a way that they're most comfortable
00:01:42.360 with but sometimes relationships can be
00:01:52.040 complicated so as I stand Here speaking to all you lovely folks today uh I'm sure you also
00:01:59.320 are getting deeper and deeper and deeper in emails despite their usefulness there's
00:02:06.200 a lot of different emails uh fighting for your attention so it's very easy uh to get overwhelmed so maybe a better way
00:02:12.640 to put this is I'm in love with the idea of
00:02:18.840 email so today I'll be covering uh how we can use a framework in rails called
00:02:24.840 action mailbox to parse inbound emails uh I will show a couple of
00:02:30.319 different practical use cases uh we'll go over how you can send these inbound emails to your application uh how
00:02:36.680 they're processed and some tips for uh running and deploying this in
00:02:43.239 production so first off what is it uh one of the most common things that I hear from people is I've heard about
00:02:49.920 action mailbox but that's usually about it uh most people don't really know about it but a simple explanation is uh
00:02:58.599 action malm will route inbound emails uh to controller like mailboxes for processing in your rails
00:03:05.239 app your application will create an inbound email record that will be later
00:03:10.280 picked up and processed in the background with active job so this provides us with a really
00:03:16.239 familiar and intuitive way uh to handle and parse these emails and still have it
00:03:22.680 feel like rails so basically this gives us an
00:03:27.879 endpoint that will accept request data uh save it process it in the background
00:03:34.519 and this is something that anyone in the world can submit to without requiring an account verification API key uh everyone
00:03:42.879 can just send we don't need a lot of the overhead that you normally have with your typical
00:03:50.519 application so since most people don't really know uh much about action mailbox or have never really worked with it uh I
00:03:56.840 have a few practical examples uh to show you some ways that I've uh used it in the past and hopefully give you uh some
00:04:03.439 more ideas to to take away for ways that you may be able to use it in your own
00:04:11.480 application so the first example this is probably uh the most common one this was one of the first ones that I I set up
00:04:18.079 and uh has been one of the most helpful ones uh by far so this is uh an example of how we
00:04:26.520 would do something like parsing a PDF attachment that was sent in the inbound email uh creating a legacy document
00:04:33.720 which which is a model that I have set up in the application uh and then create a active storage attachment from the
00:04:40.840 attachment in the inbound email things like embedded images or
00:04:46.080 signatures uh can be an issue so this is a slightly abbreviated example uh but
00:04:53.199 we're able to do one of the most common tasks for applications uh all through email uh we also have the benefit of not
00:05:01.400 choking up our web server if someone tries to upload uh a obscenely large PDF
00:05:06.520 document which I'm sure most of you have ran into at some point so this is also going to process it in the background uh
00:05:13.000 we don't need views we don't need to worry about error handling uh and again this is a way that the users can feel
00:05:19.720 more comfortable be able to get the functionality and accomplish their task
00:05:24.960 without even having to log in or even see your application at all
00:05:32.520 and here we have a example of a lightweight email to SMS service so for this example you would
00:05:39.960 include your number uh you would like to send the text message to uh in the subject of the email and the message you
00:05:46.000 would like to send in the body so just like that we have a uh Standalone
00:05:51.120 mailbox uh converting one channel to another uh all in just a few lines of uh
00:05:56.520 Ruby code
00:06:02.479 with action mmox we can also create our very own AI wrapper application so this would be an example
00:06:10.080 of uh sending an inbound email uh parsing out the body contents of the email uh sending it to open AI uh I'm
00:06:18.919 sure whichever version uh is up there is way outd at this point uh but this did work at some
00:06:24.960 point and these are a few different examples of uh how we can show the
00:06:30.319 diverse and really targeted functionality that we can accomplish with action
00:06:43.759 mailbox so this was a new mailbox uh actually set up for a demo production app uh that's been running live the past
00:06:50.319 couple days uh some of you may have interacted with it um some of you may have not but uh basically I had it set
00:06:57.000 up to where uh we had Easter eggs and would also send you out informational emails and this breaks it down a little
00:07:04.000 bit uh how all that would work so someone would email food at inbound.
00:07:10.199 action mailbox. proo or coffee and receive a transactional email back with uh options within a 10-minute
00:07:18.960 walk from E toown the Easter egg was in the reply to
00:07:25.319 for the outbound email so if someone replied to the email they would either go to winter winter lunch or dinner or
00:07:34.240 death before decaf at the application sign uh the first one to email in uh
00:07:39.800 would receive a gift card back and if you figured out the Easter egg and you tried to email back in afterwards uh you
00:07:45.800 would see that the promotion or the deal has already
00:07:51.400 expired and this is the actual code uh that was running uh the production app
00:07:56.680 so uh this is not cleaned up uh as much as I would like it to be uh but with uh
00:08:03.039 3 or four days of Live use in a production environment um and a handful of gross if El statements uh we were
00:08:09.919 able to uh add a um a usable and functional feature that didn't require
00:08:16.520 people to sign up or confirm their email uh they were just able to interact with it and then get the benefit from
00:08:27.120 it so now that you have a two different ideas of ways you can use action mailbox
00:08:32.440 in your application let's let's take a look at what happens when an inbound email is sent and how it's going to be
00:08:38.839 processed to your rails application so this is the overall flow
00:08:46.480 of what happens when an inbound email is sent to uh your uh mail
00:08:52.880 provider if you look at the documentation they uh will refer to this as an Ingress um I'll be using Ingress
00:08:59.519 and email service provider a little interchangeably here uh just because I feel most people have a better idea of
00:09:05.040 email service provider so uh for this example we send the inbound email
00:09:10.560 postmark or your chosen provider will receive it they do a little bit of processing send an inbound web hook to
00:09:17.880 your rails application uh then we authorize it uh we create a new action
00:09:23.079 mailbox inbound email it's routed and then finally sent to the mailbox for process
00:09:33.560 so taking a little deeper look into some of the steps here um it all begins with sending an inbound email uh and again
00:09:40.800 this is done with your chosen mail client so uh we don't have to worry about browser compatibility or a lot of
00:09:47.079 the other things that you may run into with typical applications we also have the benefit of leveraging email uh so
00:09:54.079 things like offline messages or sending or receiving whenever you reconnect uh
00:09:59.560 are all kind of handled automatically by your email
00:10:07.200 client so after your service provider receives the email uh each one is a little bit different typically they'll
00:10:12.760 do a little bit of processing uh and then send the web hook request with the data to your rails
00:10:19.320 application because it all web hook based uh in a pinch uh you can actually
00:10:25.399 upload a INR or some other Tye some other type of uh secure shell uh to
00:10:32.160 allow the actual mail service to send this these inbound emails to your local environment so it gives us tools that
00:10:38.800 we're comfortable with uh and that we're we're all able to work with uh in a pretty familiar
00:10:48.639 way and this is the point where the rails application actually takes over and will handle everything throughout
00:10:54.160 the rest of the process so the application receives the
00:10:59.440 hook uh if you see here at the bottom uh we see action mailbox colon and then password uh this is how the web hook
00:11:06.600 will authenticate the request so we set this value in uh either the encrypted
00:11:13.360 credentials or you could set an environment variable uh that maps to that
00:11:24.680 password so now that you all are so excited about action mailbox
00:11:30.000 right yeah I I could tell by the laughs uh so to get started uh again it's a really familiar rails process uh we run
00:11:38.519 the generators then we will uh set up our routing to tell it how to deliver it to a specific mailbox and then implement
00:11:45.920 the Parson modu like most great rails tools uh we
00:11:52.079 have uh some nice generators uh to get everything set up and installed um this
00:11:57.240 is pretty much it so in two commands uh we can get 80% of the way to having a
00:12:02.560 working uh inbound email parsing application uh bolted on to our existing
00:12:07.720 rails app or for new rails
00:12:16.079 application one thing that I I see tripping a lot of people up um if you notice here after we run the uh install
00:12:24.360 command uh you may notice that active storage is installed and the reason for
00:12:29.639 that is action mailbox will save the raw data from the inbound email request as
00:12:36.920 an active storage attachment and I've noticed this catches a lot of people off guard and uh can be
00:12:43.240 responsible for for some odd issues uh once you move everything to production uh but I'll I'll have a little bit more
00:12:49.120 on that uh towards the
00:12:56.040 end so this is one of the uh migrations that gets created uh after running our
00:13:01.079 generator and this is the uh kind of the bread and butter of the uh action
00:13:06.160 mailbox application this creates the inbound emails table and looking at
00:13:11.320 everything it's pretty straightforward um for something like email I feel like most people kind of write it off as is
00:13:17.720 weird or complicated or um something that doesn't feel like they're used to
00:13:23.240 but looking at this um we just have a status which will tell you whether it needs to be processed whether it's
00:13:29.600 bounced a message ID to ensure that each me message is going to be unique
00:13:35.839 and uh don't see it here but uh there's also the raw data attachment that
00:13:40.920 attaches the uh email data to the inbound email
00:13:50.560 object besides of migrations uh running the generators will also create a application mailbox for you this is
00:13:58.279 where all the routing for our emails will take place so you'll see uh the
00:14:03.519 generated file uh includes a commented out example of how you would match and
00:14:09.839 Route One of These inbound emails to a specific
00:14:19.120 mailbox so once everything is set up uh we have everything in place to begin generating these individual mailboxes
00:14:25.720 that's going to contain the business Logic for actually parsing out the email
00:14:32.519 now everything is going to take place within the process method um and if you've ever worked with active job uh
00:14:39.160 it's going to feel really similar uh we have a lot of the same benefits like uh before Hooks and everything is kind of
00:14:46.079 contained within this process method so again we're sticking to patterns that uh feel really comfortable and uh familiar
00:14:53.560 to most rails Developers
00:15:01.680 so moving on to the next step here uh once the uh your application has
00:15:06.720 received the inbound email uh it will actually process it asynchronously so we
00:15:11.800 we won't be processing the email right away what happens is we save the inbound
00:15:16.920 email uh the bulk of the the data is stored in the Raw data attachment which is from active storage and then we enq a
00:15:24.880 job to be processed later
00:15:32.560 and this is where a lot of the magic happens um one of my favorite things is the fact that uh a model that's
00:15:40.880 responsible for the majority functionality for this uh subf framework in rails can fit on a single
00:15:50.800 slide so let's look into a little more detail about some of these different
00:15:56.720 sections so after our table definition uh we have a few different concerns
00:16:02.000 being included here the first one uh incinerable will ensure that the inbound
00:16:08.839 email uh is scheduled for incineration uh whenever the status has been changed to
00:16:14.160 processed so because these because the inbound emails are stored as an active
00:16:19.440 storage attachment uh this is going to automatically make sure that your S3 bucket uh doesn't overflow with emails
00:16:26.160 after however long you've had it running so within 30 days the raw data from the attach from
00:16:32.800 the email uh will be automatically deleted and cleaned up so one less thing you have to worry
00:16:40.079 about and again the message ID is um uh to ensure that there's a unique
00:16:45.240 identifier for each email uh this is how we uh can identify one email and Link
00:16:50.519 them to others and be able to determine if it's a reply to a single email or
00:16:56.040 part of a longer thread or chain of emails
00:17:01.279 and finally the routable concern uh is what handles routing the inbound email
00:17:07.919 to our mailbox and then finally delivering it to its final destination in the mailbox for
00:17:19.039 processing so here's the raw email uh active storage attachment I mentioned
00:17:24.160 earlier um so this is uh going to be stored from the uh mail data that gets
00:17:29.520 sent from the email service provider uh it's pretty equivalent to uh if you've ever worked with the Ruby mail object uh
00:17:35.799 just calling mail. 2s so if you see all that out output that's basically what we're going to save in this raw email
00:17:42.640 active storage attachment you can see we also have uh we're specifying the service here so uh
00:17:49.919 if say you want to use uh maybe a less durable or cheaper solution just for parsing these emails uh we can also set
00:17:57.000 this up uh to go to a specific Destin a and not have to worry about it uh dealing with our main active storage
00:18:03.720 service that we may have set
00:18:09.240 up and here are a few examples of how you might use uh some of the methods that were defined in this
00:18:20.080 class so if we call Raw email this is going to return the active storage
00:18:25.159 attachment created from the raw email data so Source will um convert the raw
00:18:31.960 email data uh to a string uh and this is really helpful because this will allow us to pass it into the rails conductor
00:18:39.440 uh which has a source option so we can hand it a giant uh blob of text that
00:18:45.679 basically maps to the email and it will simulate it sending to our uh application in our development
00:18:53.559 environment and for mail when we're in the context of the actual mailbox uh
00:18:59.559 calling mail just returns a normal mail message in Ruby so this would be the same one that you use in uh uh active
00:19:06.600 mailer or uh any other mail service that you may have interacted with or or had to use with Ruby
00:19:17.840 before so now we have a little bit more background on the action mailbox inbound
00:19:23.000 email and how it's created let's look at how the inbound email will be routed to the mailbox for its final
00:19:30.679 processing so again the the job is uh added and created After we receive the inbound email and processed in the
00:19:44.799 background your uh application mailbox is basically like the post office for
00:19:50.480 your action mailbox app it's going to receive all of your inbound emails and decide uh where and how to route it to
00:19:57.520 its final destination uh this is actual uh a a real example
00:20:02.919 from a snippet of the public uh the public mailboxes for the uh production
00:20:08.200 app that I set up so one of the things that you may notice
00:20:14.520 um we're using uh a pretty light regex for most of these options but at the
00:20:20.240 bottom here we're using the All method so this ensures that if we don't have a match by the time we get to the
00:20:26.840 bottom uh any and all email that get to that point will be routed to the promotions so this is a great way to set
00:20:34.360 up something like a a catchall mailbox or an unroutable email mailbox uh to
00:20:39.919 ensure that whenever you do get these emails uh you can at least have some type of manual intervention before
00:20:46.520 Markin them is bounced or failed or whatever so this gives us a way to capture everything and be able to uh
00:20:53.559 kind of Ruby our way out of a problem if we need to
00:21:03.840 so after we route the inbound email to the mailbox uh this is when we begin the actual business logic or processing of
00:21:11.120 the email and this is where all the magic
00:21:17.600 happens uh everything is going to be contained within that single process method and uh again if you've worked
00:21:24.039 with active job this is going to feel very familiar uh has a lot of the same life cycle hooks then we can run uh
00:21:30.840 either before or after the processing of the email to ensure that all of our data is either set up correctly or torn down
00:21:40.679 correctly action mailbox also provides us with a really handy method uh called Bounce with and what this will do this
00:21:48.240 will automatically Mark the inbound email is bounced so we don't try to reprocess it uh it also gives us a uh
00:21:54.799 easy way to query for any type of inbound email it may have bounced and it takes a uh rails mailer and uses
00:22:03.440 that mailer to reply back to the sender to alert them of the bounce so again we have a one a nice oneliner to Mark the
00:22:11.360 email as bounce and also alert the sender of the status of the the failed to
00:22:21.080 email so here's an example of how you might combine the before processing life
00:22:26.279 cycle hook uh with the bounce width method so this is a uh pretty common use case
00:22:32.400 um action mailbox is great but you may not want to randomly accept attachments from anyone who emails into you so for
00:22:40.720 this example uh before we do any processing in the mailbox uh this insure
00:22:46.080 user method is going to run so for this we're going to parse out the uh sender
00:22:52.039 email address and we're going to see if we have a valid user from it and if not uh we're going to use the bounce width
00:22:58.080 method passes the mailer uh and mark the email is bounced and alert the sender all in
00:23:03.520 one
00:23:09.520 line what good is a toy without batteries now that you all know so much about action mail moox you're going to
00:23:16.000 want to deploy it somewhere and R provides some great
00:23:21.840 options uh right out of the box there's also uh some third party gems available
00:23:27.120 for other services like Amazon sces uh but these ingresses um are basically a
00:23:33.480 collection of controllers that are specific to the provider and allowing you to focus on the business logic so
00:23:40.600 you don't have to reimplement everything uh if you decide to switch mail providers uh basically at any
00:23:52.840 time so now that we're deploying our action mailbox app to production uh there's a few potential pitfalls that uh
00:24:00.200 you may want to watch out for so the first one because the inbound
00:24:05.720 email is stored as an active storage attachment um uh your active storage URL
00:24:12.039 options uh won't be set by default so if you're trying to create a new attachment or return some type of Link um normally
00:24:19.039 the active storage um URL options are are set somewh your application controller but since we're processing
00:24:25.480 the email in the context of a of a job uh many times that value isn't set so
00:24:31.000 checking to make sure that your active storage URL options are set before you try to generate new attachments or send
00:24:37.960 those out uh is an easy way to save yourself a lot of
00:24:43.080 headaches another option is you'll probably want to set up something besides disk for your active storage
00:24:49.960 service um most of the time this will be issues if you're deploying your application to somewhere like Heroku uh
00:24:56.440 especially if you're running sidekick uh and background so uh whenever the inbound email is processed it's going to
00:25:02.000 look for the uh actual file that's on your web Dyno so it won't be able to find it and it'll throw an err and you
00:25:09.760 pull your hair out and wonder why you can't get this thing to work personal
00:25:16.159 experience uh the other uh big tip that uh I really suggest to everyone um is
00:25:22.000 right from the beginning uh plan on routing your inbound emails through some type of subdomain uh this can really be
00:25:28.960 anything but it makes it much easier to diagnose
00:25:35.000 uh any type of uh DNS issues that you may be running into when setting everything up and it also prevents
00:25:42.279 yourself from breaking your existing MX records and not having your email work
00:25:47.640 again personal
00:25:54.960 experience so we've covered some practical examples but this being a ruby
00:26:01.039 conference I thought it would be only proper to send people away with some impractical
00:26:07.679 examples so what follows are some of the uh goofiest impractical and weird ideas
00:26:15.840 I could possibly think of and get working uh around inbound emails so I hope this uh one gives you
00:26:24.399 all a little bit of entertainment but uh really I I hope this Sparks my is for some ways that you can take away and
00:26:30.880 maybe relate it to your own application uh to create your own features weird or
00:26:40.919 not okay this one is actually live uh very lightly tested uh
00:26:47.399 but uh catfax on demand uh this QR code should should work uh but by sending an
00:26:54.919 inbound email to Cat-Back inbound . action mailbox Pro uh
00:27:00.720 will make a request to a catfax API take the response and then email it back to
00:27:10.200 you and this is what that would look like uh in the context of the the actual
00:27:17.640 mailbox so not only a handful of lines uh we're able to create our very own automated catfax as a service platform
00:27:25.919 um I'm still waiting for funding if anyone has leads you can let me know
00:27:34.720 afterwards the age guesser um it always seems to guess
00:27:42.039 older so just this is not something I uh personally sent up but this will uh
00:27:47.760 reach out to the agfi API and uh try to guess your age based
00:27:53.480 on your email and how we do that is uh this will actually parse out the display name for
00:28:00.240 your email so if you have that set up uh we'll try to pull that out and if not we're going to uh we're going to split
00:28:06.200 the string of the email address and we're going to take the first portion so we at least have something to send
00:28:14.440 over and again this is a uh live mailbox this is the exact code uh that should be
00:28:20.000 interacting with the email address that you all would send in but we uh
00:28:28.919 uh we make the request with HTTP party we have our URL and at the bottom here
00:28:34.799 this name method uh we have we're going to try two
00:28:39.840 different ways to try to pull out the display name so the first one you'll see this is male and then we're passing a
00:28:46.200 bracket with from uh this is a male field which is a
00:28:51.559 little bit different than some of the other uh mail methods that you may run into uh but this is how we uh can parse
00:28:58.559 out just see first and the last name if you have that set in your email and we send that out so this is a way that we
00:29:05.760 can get additional information from the user without requiring them to to do
00:29:10.919 anything extra all they have to do is send an email and we're going to do our best to figure out their name and then
00:29:17.960 send it send it to the API for a guess and then reply back
00:29:28.279 this is where it starts to get more and more impractical uh mail yourself a postcard
00:29:34.799 reminder so I don't know if any of you have uh maybe emailed yourself a
00:29:39.880 reminder or a note or something at a conference and then by the time you get home it's it's way way down in your
00:29:45.760 inbox and you can't really find it this takes the Impractical approach
00:29:50.960 this one's not set up live but this takes the Impractical approach of parsing at the body uh of
00:29:58.080 your reminder email and we'll actually send a physical postcard to your
00:30:05.480 house so now we're taking our digital email and crowding up our physical mailbox as
00:30:15.559 well uh this is using the lob API um this was working at some point it's been
00:30:22.240 a uh couple months since I've tested it but um this takes a uh an image which is
00:30:27.440 an S3 bucket that we have set up uh and the message uh you have to do some very specific HTML for all the layout but um
00:30:35.840 by sending an email like this we would eventually get something
00:30:41.159 like this in our mailbox uh five to seven days extremely impractical but a lot of
00:30:52.840 fun speaking of Impractical and a lot of fun uh this is my favorite example by
00:31:04.919 far uh this is uh an abbreviated examp example for obvious
00:31:12.519 reasons but a few months ago I discovered the remote start and
00:31:17.600 monitoring device uh on my truck has some undocumented API in
00:31:23.519 points and I started wondering if I would be able to integrate these with emails some
00:31:29.120 somehow so for this example the truck mail box you would just send inbound email to truck at whatever uh and
00:31:37.000 actually have it make a request to the remote start API and fire up my
00:31:46.480 truck I think this is a great example of a problem that we don't need to
00:31:53.200 solve but we really want to and I think those those are some of
00:31:58.240 the the best problems that programmers deal with when you want something to work because you want this to exist
00:32:04.279 whether it's useful or not this was a lot of fun to get working
00:32:11.960 um I know that you know the the slide probably looks really nice and all that but uh it doesn't quite do it
00:32:20.919 justice let's see how it turned
00:32:26.399 out here we have my 2006 Toyota Tacoma outfitted with an aftermarket remote
00:32:32.279 start I'm going to send an inbound email to our truck mailbox and with the luck
00:32:37.960 be able to start the
00:32:43.320 truck uh you may have noticed there's no keys in the ignition here uh I'm going to try to send an invalent email to the
00:32:49.760 track mailbox uh we'll probably take a couple minutes for it to uh complete process but uh if everything goes well
00:32:56.399 uh we should be able to start the track truck here so let's see email sent now we
00:33:06.200 wait
00:33:15.760 sure my friends on with down email and why I
00:33:21.960 love action mailbox
00:33:29.279 um if you happen to be staying at the Boulderado and look across the street uh you may notice this machine um again
00:33:36.960 it's not hooked up don't send the email but it is one of the weirdest
00:33:44.000 things uh I've actually been able to get working uh by sending an inmal
00:33:50.880 email so you may have a complicated relationship with email but uh that doesn't mean your application has to
00:33:58.240 so in a handful of slides we've been able to cover everything from API responses document uploads postcard
00:34:05.240 reminders and and even starting a truck and these are all things that people can do without requiring registration uh or
00:34:11.520 even having to look at your application these are a few of the
00:34:16.639 reasons why I love action mailbox and hope you all begin to feel some of the love
00:34:22.720 too so these are a couple of ways to find me uh you can find me at my website and on Twitter uh if you would um like
00:34:31.119 to reach out I'd be more than happy to connect with any of you and since everyone is going to ask one more action
00:34:38.760 mailbox inbound email setup uh if you email slides at inbound. action mailbox.
00:34:45.200 proo uh you will receive a link for the slides um probably from 11 or so I'm a
00:34:52.919 incessant tinkerer with my slides so they may be a little bit outdated but this will email you back uh this speaker
00:34:57.960 deck where the slides are already uploaded uh so you can have access to those when whenever you get
00:35:03.560 home that's it thank
00:35:14.240 you the the question was how many emails did it take uh to actually get the the
00:35:20.800 the truck part working um I I lost track uh this was uh something that I I tried
00:35:28.000 to have for ready for uh rails comp um I think I left on Monday this was recorded
00:35:34.119 Friday at 4:30 p.m. so this was my last ditch effort um but uh
00:35:41.000 luckily uh the API had a couple of easier end points to kind of interact
00:35:46.680 with there was a lock and unlock one and then uh I think one that would return the battery level so I kind of played
00:35:53.440 with those first um without having to burn out the battery on my truck and
00:35:58.680 once I was able to get a couple of those working I would you know at least kind of assuming that I would be able to uh
00:36:04.599 and then uh to make sure that my truck doesn't get started whenever someone sends me a Spam inbound
00:36:11.160 email to to actually get everything working uh I ran everything through ingro on my local setup so as soon as it
00:36:17.960 was as soon as it was done recorded killed the ingro server uh and no one
00:36:23.119 has access to that URL ever again thankfully so that's one thing where I um really
00:36:31.480 try to lean on the mail provider they do a lot of like scanning and uh the dkim and SPF verification a lot of that
00:36:38.800 information is going to be in the headers of the emails so it lets you get as grle as like you feel like you you
00:36:45.200 may need to but we can also kind of lean on a few assumptions like when someone sends us
00:36:51.000 an inbound email we can probably assume that that's a valid email and send it back and if not it's kind of on them
00:36:57.640 they're they're the one that's spoofing everything so um for the security thing if you uh start to to get a little you
00:37:06.520 know hesitant about just randomly accept accepting stuff uh the before processing Hook is your best bet to uh start
00:37:13.560 refining everything uh check for a valid user account uh you can check that there is an attachment check that uh the
00:37:19.800 attachment is a PDF or CSV or whatever type um so in the life cycle hooks uh
00:37:25.640 this gives you a chance to uh verif everything is there and is at least secure enough uh before you begin the
00:37:33.240 processing uh the question was uh is there a way that we can uh receive the emails directly and um kind of
00:37:39.680 circumvent or skip the email service providers um so yes and no um we would
00:37:46.359 be able to do that um I think uh that's how a lot of the inbound email processing was done prior to action
00:37:52.359 mailbox um basically just uh web hook data uh that get sent to your application so
00:37:58.160 uh as long as you have some type of endpoint to feeli that request and some way to um parse the uh it's usually the
00:38:04.839 raw attachment data uh because it has to match the uh official email spec um then
00:38:10.119 you should be able to save it so with the string we can create a ruby mail object from there and then forward that
00:38:16.960 on to yourself or forward that to your support team uh and then that's the point where it it starts feeling more
00:38:22.720 like action mailer instead of mailbox so this gives us a a way to be able to
00:38:27.920 handle that easily all right one more question yes is there any like first class support
00:38:34.000 for calendar attachments um I don't believe so um I
00:38:42.000 know that there are um I've used a few of the the gems that are out there to send the attachments in the different uh
00:38:48.760 calendar formats in there um but your reply is basically like a normal email
00:38:54.359 so if you if you're able to generate the the IC uh attachment or one of the other ones you could include that in the email
00:39:01.359 but I've also found that uh most of the email clients are also smart enough uh if you put a date in there uh it'll
00:39:07.319 normally turn into like a little hover where you can automatically add that to your calendar so that's another way
00:39:12.560 where we can leverage what's already there in the email clients and not have to uh kind of build everything from
00:39:21.640 scratch thank you
00:39:27.560 I
Explore all talks recorded at Rocky Mountain Ruby 2024
+18