<div><div><span><div><div><div>
<div>
<span>Hi Stephen,<div><br></div><div>Here you go. Here's some code adapted from one of our apps.</div><div><br></div><div>I actually had to hack net/smtp to get AUTH PLAIN to work against our mail server.</div><div>I omitted the changes here as I imagine it's not a common problem.</div><div><br></div><div><span><div>Cheers,</div><div><br></div></span><span>-- Dave<br></span></div><div><font class="Apple-style-span" face="Menlo"><font class="Apple-style-span" face="Helvetica"><br></font></font></div><div><font class="Apple-style-span" face="Menlo">#lang scheme/base</font></div><div><font class="Apple-style-span" face="Menlo"><br></font></div><div><font class="Apple-style-span" face="Menlo"><div>(require (prefix-in net-head: net/head)</div><div> net/smtp</div><div> openssl) </div></font></div><div><font class="Apple-style-span" face="Menlo"><br></font></div><div><font class="Apple-style-span" face="Menlo">; #:from string</font></div><div><font class="Apple-style-span" face="Menlo">; </font><span class="Apple-style-span" style="font-family: Menlo; ">#:to string</span></div><div><span class="Apple-style-span" style="font-family: Menlo; ">; #:subject string</span></div><div><span class="Apple-style-span" style="font-family: Menlo; "><span class="Apple-style-span" style="font-family: Helvetica; "><div><span class="Apple-style-span" style="font-family: Menlo; ">; [#:cc (U string #f)]</span></div></span>; [#:smtp-server string]</span></div><div><span class="Apple-style-span" style="font-family: Menlo; "><span class="Apple-style-span" style="font-family: Helvetica; "><div><span class="Apple-style-span" style="font-family: Menlo; ">; [#:smtp-username string]</span></div></span><span class="Apple-style-span" style="font-family: Helvetica; "><div><span class="Apple-style-span" style="font-family: Menlo; ">; [#:smtp-password string]</span></div></span>; string</span></div><div><span class="Apple-style-span" style="font-family: Menlo; ">; -></span></div><div><span class="Apple-style-span" style="font-family: Menlo; ">; void</span></div><div><div><font class="Apple-style-span" face="Menlo"><div><div>(define (send-email</div></div><div> #:from from</div><div> #:to to</div><div> #:cc [cc #f]</div><div> #:subject subject</div><div> #:smtp-server [smtp-server "smtp.example.com"]</div><div> #:smtp-username [smtp-username "foo"]</div><div> #:smtp-password [smtp-password "bar"]</div><div> content)</div><div> (let ([recipients (cons to (if cc (list cc) null))]</div><div> [headers (net-head:standard-message-header</div><div> from</div><div> (list to)</div><div> (if cc (list cc) null)</div><div> null ; bcc</div><div> subject)])</div><div> (smtp-send-message</div><div> smtp-server</div><div> (strip-friendly-names from)</div><div> (list* (strip-friendly-names to)</div><div> (if cc</div><div> (list (strip-friendly-names cc))</div><div> null))</div><div> headers</div><div> (regexp-split #rx"\r?\n" content)</div><div> #:auth-user smtp-username</div><div> #:auth-passwd smtp-password</div><div> #:tls-encode ports->ssl-ports)</div><div> (void)))</div><div><br></div><div>; Strips friendly names from an email address if present, for example:</div><div>; Dave <dave@example.com> -> dave@example.com</div><div>; dave@example.com -> dave@example.com</div><div>;</div><div>; string -> string</div><div>(define (strip-friendly-names email)</div><div> (match (regexp-match #px"^.*[<](.*)[>]$" email)</div><div> [(list _ ans) ans]</div><div> [#f email]))</div></font></div></div><div><font class="Apple-style-span" color="#A0A0A0"><font class="Apple-style-span" color="#000000"><br></font></font></div></span>
</div>
</div></div></div></span></div></div>