Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-09 Thread Philip McGrath
I put up an example taken from my code for Digital Ricoeur in response to
an old mailing list thread
. It
is not ready for general-purpose use—in particular, I basically only have
to deal with trusted input—but here it is:
https://github.com/LiberalArtist/multipart-writing-examples

That thread also has some discussion about what a good package might want
to address and some slightly annoying differences between "normal" mime and
"multipart/form-data" used for web forms.

-Philip


On Thu, Apr 9, 2020 at 10:25 AM Matthew Flatt  wrote:

> At Thu, 9 Apr 2020 07:09:21 -0700 (PDT), Brian Adkins wrote:
> > I looked at the net/mime library, but, as the title of the doc page
> > suggests, it seemed to only be about decoding, not creating:
> >
> > https://docs.racket-lang.org/net/mime.html?q=net%2Fmime
>
> Ah, right. I think I've made this mistake before.
>
>
> Encoding is be built into SirMail (very old code):
>
>  https://github.com/mflatt/sirmail/blob/master/sirmail/sendr.rkt#L136
>
> It would make sense to have a better version of this in a package, of
> course.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/5e8f303a.1c69fb81.69759.d940SMTPIN_ADDED_MISSING%40gmr-mx.google.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAH3z3gaDENPvEyzQ5jgD1ymm4Vep22kYSiTf2PNtDvLvQrTfOA%40mail.gmail.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-09 Thread Matthew Flatt
At Thu, 9 Apr 2020 07:09:21 -0700 (PDT), Brian Adkins wrote:
> I looked at the net/mime library, but, as the title of the doc page 
> suggests, it seemed to only be about decoding, not creating:
> 
> https://docs.racket-lang.org/net/mime.html?q=net%2Fmime

Ah, right. I think I've made this mistake before.


Encoding is be built into SirMail (very old code):

 https://github.com/mflatt/sirmail/blob/master/sirmail/sendr.rkt#L136

It would make sense to have a better version of this in a package, of
course.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/5e8f303a.1c69fb81.69759.d940SMTPIN_ADDED_MISSING%40gmr-mx.google.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-09 Thread Brian Adkins
On Thursday, April 9, 2020 at 8:47:09 AM UTC-4, Matthew Flatt wrote:
>
> At Wed, 8 Apr 2020 21:28:11 -0400, George Neuner wrote: 
> > There's nothing in Racket for MIME that I'm aware of 
>
> There's a `net/mime` library. 
>
> I'm replying with an attachment so you can see what it generates, since 
> my email client uses that library. 
>
>
> Matthew 
>

I looked at the net/mime library, but, as the title of the doc page 
suggests, it seemed to only be about decoding, not creating:

https://docs.racket-lang.org/net/mime.html?q=net%2Fmime

Are the functions for creating multipart email messages documented 
elsewhere?

Thanks,
Brian

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/a80d82e5-17f4-4e5e-b41b-4a809a6bd954%40googlegroups.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-09 Thread Matthew Flatt
At Wed, 8 Apr 2020 21:28:11 -0400, George Neuner wrote:
> There's nothing in Racket for MIME that I'm aware of

There's a `net/mime` library.

I'm replying with an attachment so you can see what it generates, since
my email client uses that library.


Matthew

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/5e8f1949.1c69fb81.5d1a9.7638SMTPIN_ADDED_MISSING%40gmr-mx.google.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-09 Thread Hendrik Boom
On Wed, Apr 08, 2020 at 09:28:11PM -0400, George Neuner wrote:

> 
> There's nothing in Racket for MIME that I'm aware of ... but then multipart
> formatting is needed only for multi-version messages, or for embedding
> non-text data (graphics, etc.) into a message.   Since so many people read
> mail in web browsers, and most offline clients handle HTML, I don't think
> many people even bother with multi-version messages any more.  Sending plain
> HTML is as easy as sending plain text.

But receiving HTML has security issues.  I prefer to avoid it.

I rarely read the HTML parts of multi-version messages.

-- hendrik

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200409123948.pwrihetsjqxwwwgt%40topoi.pooq.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-08 Thread George Neuner


On 4/8/2020 6:09 PM, Brian Adkins wrote:


Thanks for the info George. Are you feeding that entire template 
(after substituting the @ variables) into the smtp-send-message 
function as the message argument i.e. a list of lines?


Yes.


I'm also curious about having "subject" in the template vs. the header.


History.  When I first did this (many years ago) there was an issue with 
/standard-message-header/  screwing up the line breaks, and the 
resulting message being formatted incorrectly if there was a non-empty 
subject string.


I am sure this has long been fixed, but at the time I started 
constructing my own header strings using /insert-field/  from the 
net/head library.  Message[*] headers can be in any order - they need 
only to precede the body - so it didn't really matter where the subject 
line came from, and since the subjects were static for most of my 
messages, it was simplest to just put them into the message templates.


[*] Note that embedded MIME multipart headers DO have defined order.


I take it from your reply there isn't already something in existence 
that streamlines this process in a similar way to a framework such as 
Rails.


Don't get me started on Rails  8-(  Makes easy things easy and hard 
things damn near impossible.



There's nothing in Racket for MIME that I'm aware of ... but then 
multipart formatting is needed only for multi-version messages, or for 
embedding non-text data (graphics, etc.) into a message.   Since so many 
people read mail in web browsers, and most offline clients handle HTML, 
I don't think many people even bother with multi-version messages any 
more.  Sending plain HTML is as easy as sending plain text.


Multipart formatting is recursive and parts can be nested arbitrarily, 
so handling it all properly could be complicated given the need to 
integrate with other code generating the message body (HTML, etc.) 
within.  It's doable ... I just never got the urge to tackle it.


George

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/93536d3e-28be-bb37-4ad1-e92d29a573c5%40comcast.net.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-08 Thread Brian Adkins
On Wednesday, April 8, 2020 at 6:09:14 PM UTC-4, Brian Adkins wrote:
>
> On Wednesday, April 8, 2020 at 1:46:43 PM UTC-4, gneuner2 wrote:
>>
>>
>> On 4/8/2020 12:54 PM, Brian Adkins wrote: 
>> > I was able to write a simple wrapper around smtp-send-message and get 
>> > it working through SendGrid in a few minutes (see below), but I wasn't 
>> > able to find any examples of sending emails containing both a plain 
>> > text version and HTML version. Can anyone point me to some examples? 
>> > 
>> > Thanks, 
>> > Brian Adkins 
>>
>> You done the hard part.  Once you can send a plain text message, HTML is 
>> not much harder. 
>>
>> You have to construct a MIME multipart message, which has a particular 
>> internal structure. 
>> See: 
>>
>> https://stackoverflow.com/questions/10631856/mime-type-to-satisfy-html-email-images-and-plain-text
>>  
>> http://www.enewsletterpro.com/articles/multi_part_mime_messages.asp 
>> https://www.ietf.org/rfc/rfc1521.txt 
>>
>>
>> My solution is to use message templates like the attached - which shows 
>> using not just multipart but also embedded graphics.  My program 
>> customizes the message by substituting for the '@' preceded "variables" 
>> in the template.  Feel free to (ab)use the same style or adapt it for 
>> your needs. 
>>
>> George 
>>
>>
> Thanks for the info George. Are you feeding that entire template (after 
> substituting the @ variables) into the smtp-send-message function as the 
> message argument i.e. a list of lines? I'm also curious about having 
> "subject" in the template vs. the header.
>
> I take it from your reply there isn't already something in existence that 
> streamlines this process in a similar way to a framework such as Rails.
>

I got it to work by stuffing the right values into the header - thanks!
 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/bbd7b148-4530-4b92-9f5c-2698a0709845%40googlegroups.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-08 Thread Brian Adkins
On Wednesday, April 8, 2020 at 1:46:43 PM UTC-4, gneuner2 wrote:
>
>
> On 4/8/2020 12:54 PM, Brian Adkins wrote: 
> > I was able to write a simple wrapper around smtp-send-message and get 
> > it working through SendGrid in a few minutes (see below), but I wasn't 
> > able to find any examples of sending emails containing both a plain 
> > text version and HTML version. Can anyone point me to some examples? 
> > 
> > Thanks, 
> > Brian Adkins 
>
> You done the hard part.  Once you can send a plain text message, HTML is 
> not much harder. 
>
> You have to construct a MIME multipart message, which has a particular 
> internal structure. 
> See: 
>
> https://stackoverflow.com/questions/10631856/mime-type-to-satisfy-html-email-images-and-plain-text
>  
> http://www.enewsletterpro.com/articles/multi_part_mime_messages.asp 
> https://www.ietf.org/rfc/rfc1521.txt 
>
>
> My solution is to use message templates like the attached - which shows 
> using not just multipart but also embedded graphics.  My program 
> customizes the message by substituting for the '@' preceded "variables" 
> in the template.  Feel free to (ab)use the same style or adapt it for 
> your needs. 
>
> George 
>
>
Thanks for the info George. Are you feeding that entire template (after 
substituting the @ variables) into the smtp-send-message function as the 
message argument i.e. a list of lines? I'm also curious about having 
"subject" in the template vs. the header.

I take it from your reply there isn't already something in existence that 
streamlines this process in a similar way to a framework such as Rails.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/420bc8df-b72f-43d9-9bf4-b5dbf2dad6ed%40googlegroups.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-08 Thread George Neuner


On 4/8/2020 12:54 PM, Brian Adkins wrote:
I was able to write a simple wrapper around smtp-send-message and get 
it working through SendGrid in a few minutes (see below), but I wasn't 
able to find any examples of sending emails containing both a plain 
text version and HTML version. Can anyone point me to some examples?


Thanks,
Brian Adkins


You done the hard part.  Once you can send a plain text message, HTML is 
not much harder.


You have to construct a MIME multipart message, which has a particular 
internal structure.

See:
https://stackoverflow.com/questions/10631856/mime-type-to-satisfy-html-email-images-and-plain-text
http://www.enewsletterpro.com/articles/multi_part_mime_messages.asp
https://www.ietf.org/rfc/rfc1521.txt


My solution is to use message templates like the attached - which shows 
using not just multipart but also embedded graphics.  My program 
customizes the message by substituting for the '@' preceded "variables" 
in the template.  Feel free to (ab)use the same style or adapt it for 
your needs.


George


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/b58bf51b-e970-1c54-bb24-e08996e43849%40comcast.net.
Subject: confirm password reset
MIME-Version: 1.0
Content-Type: multipart/alternative;
  boundary="__ALT__"

This is a MIME-encoded HTML message. If you are seeing
this text only section, your mail program either is too
old or is not configured properly.


--__ALT__
Content-Type: multipart/related;
  boundary="__REL__"

--__REL__
Content-Type: text/html; charset=us-ascii
Content-Disposition: inline
Content-ID: 



@USERNAME,

A request has been received to reset your password
   
   If you wish to reset your password, please confirm by
   clicking on the link below. Shortly you will receive
   another email containing a new password .
   


Reset My Password



   Message sent at @SEND_TIME on @SEND_DATE.
   Links will expire at @LINK_TIME on @LINK_DATE.
   If you believe you have received this message in error,
   Please contact technical support and reference @REFERENCE.
   




--__REL__
Content-Type: image/jpeg
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-ID: 

  base64 encoded logo image goes here
  reference in body as 

--__REL__
--__ALT__--


[racket-users] Examples of sending HTML email w/ Racket?

2020-04-08 Thread Brian Adkins
I was able to write a simple wrapper around smtp-send-message and get it 
working through SendGrid in a few minutes (see below), but I wasn't able to 
find any examples of sending emails containing both a plain text version 
and HTML version. Can anyone point me to some examples?

Thanks,
Brian Adkins


#lang racket/base

(require net/head
 net/smtp
 openssl
 racket/contract)
(require "./axio-env.rkt")

;; (module+ main
;;   (send-email "Fred Flintstone "
;;   '("Barney Rubble ")
;;   "Test message subject"
;;   (list
;;"Message line one"
;;"line two"
;;""
;;"line four")))
(define/contract (send-email from to subject message-lines)
  (-> string? (listof string?) string? (listof (or/c string? bytes?)) any)
  (smtp-send-message smtp-server
 from
 to
 (standard-message-header from to '() '() subject)
 message-lines
 #:port-no smtp-port
 #:auth-user   smtp-username
 #:auth-passwd smtp-password
 #:tls-encode  ports->ssl-ports))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/7dd13674-5f20-4e4d-92de-0da0e2bc7c95%40googlegroups.com.