# Net/smtp sending with attachments

**URL:** https://racket.discourse.group/t/net-smtp-sending-with-attachments/2181
**Category:** Questions & Answers
**Tags:** question, mime, smtp
**Created:** [July 31, 2023, 2:42pm UTC](https://racket.discourse.group/t/net-smtp-sending-with-attachments/2181 "2023-07-31T14:42:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![markshead](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/markshead/32/1334_2.png) [@markshead](https://racket.discourse.group/u/markshead)
#### Post date: [July 31, 2023, 2:42pm UTC](https://racket.discourse.group/t/net-smtp-sending-with-attachments/2181/1 "2023-07-31T14:42:47Z")

</div>

I'm trying to use net/smtp to send emails that contain calendar invites. I can't seem to find a library that with let me construct the body of an email using MIME. I can probably create what I need using [https://github.com/mflatt/sirmail/blob/master/sirmail/sendr.rkt#L136](https://github.com/mflatt/sirmail/blob/master/sirmail/sendr.rkt#L136) as a model.

But before I go down that path I wanted to ask for a sanity check to make sure I'm not overlooking an existing module or something else I should look at to handle the construction of MIME formatted emails. Any suggestions?

---

<div class="post-metadata">

### Author: ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)
#### Post date: [August 9, 2023, 1:09am UTC](https://racket.discourse.group/t/net-smtp-sending-with-attachments/2181/2 "2023-08-09T01:09:23Z")

</div>

I don't know of any existing library for MIME writing. In response to an old [mailing-list question](https://groups.google.com/g/racket-users/c/thv2fQnd0zA) from Christine Lemmer Webber, I posted some code I've written at [GitHub - LiberalArtist/multipart-writing-examples: Examples of multipart writing in Racket](https://github.com/LiberalArtist/multipart-writing-examples). (This was before Racket's license change: I'm happy to relicense it `(Apache-2.0 OR MIT)`. I'll update the repository eventually.) Do see the mailing list for some important caveats about the code and considerations for someone undertaking a general-purpose library!

The email code I posted is specific to `multipart/alternative` (e.g. sending `text/html` email with `text/plain` fallback): I think I've written versions of it that handle attachments, too, but if so I don't know where I've put them.

The code I posted also uses `net/sendmail`, but I've adapted it for use with `net/smtp`, and I do know where I've put that. I'll post it too once I've ripped out the specific email hard-coded into the script I wrote most recently.

If I were going to use the long random boundary strategy described (IIRC) in the RFC, I'd probably use my [uuid: Universally Unique Identifiers](https://docs.racket-lang.org/uuid/) library.
