Sending email while offline is relatively straight forward; there are many ways to do it. I choose to use msmtp-offline. It uses two executables, msmtp-offline and msmtp-queue to do the work. msmtp-offline is a wrapper for msmtp which attempts to send the email. If the send fails, however, unlike msmtp it will add it to a queue for sending later. That's where msmtp-queue comes in. Msmtp-queue works to flush mailboxes defined in msmtp.conf. It can flush all of some of the mail depending on how it is configured. For me, I only have one smtp server configured so I have it flush the entire queue. This keeps things simple.
The fun part of all this is setting it up to take advantage of an Internet connection the moment it becomes available. You can configure msmtp-queue to run on a schedule, but you'll want to make sure it runs frequently enough that you don't miss a window of connectivity. But, you don't want it running too frequently. Why waste the CPU cycles if you don't have to. This is why I configured mine to run as an ifup action. When a network connection comes up ifup scripts will run. I had previously configured this in order to ensure I automatically connect to my VPN server at all times. Using this experience I configured another entry to run `msmtp-queue -f` to attempt to flush the mail queue any time a network connection is detected. This, so far, has worked very well.