v8.1 #47

Merged
danieljsummers merged 4 commits from v8.1 into main 2023-07-05 00:03:43 +00:00
3 changed files with 12 additions and 7 deletions
Showing only changes of commit aee2139a9f - Show all commits

View File

@ -2,10 +2,8 @@
module PrayerTracker.Email module PrayerTracker.Email
open MailKit.Net.Smtp open MailKit.Net.Smtp
open MailKit.Security
open Microsoft.Extensions.Localization open Microsoft.Extensions.Localization
open MimeKit open MimeKit
open MimeKit.Text
open PrayerTracker.Entities open PrayerTracker.Entities
/// Parameters required to send an e-mail /// Parameters required to send an e-mail
@ -35,11 +33,13 @@ type EmailOptions =
/// The e-mail address from which e-mail is sent /// The e-mail address from which e-mail is sent
let private fromAddress = "prayer@bitbadger.solutions" let private fromAddress = "prayer@bitbadger.solutions"
open MailKit.Security
open Microsoft.Extensions.Configuration
/// Get an SMTP client connection /// Get an SMTP client connection
// FIXME: make host configurable let getConnection (cfg : IConfiguration) = task {
let getConnection () = task {
let client = new SmtpClient () let client = new SmtpClient ()
do! client.ConnectAsync ("127.0.0.1", 25, SecureSocketOptions.None) do! client.ConnectAsync (cfg.GetConnectionString "SmtpServer", 25, SecureSocketOptions.None)
return client return client
} }
@ -51,6 +51,8 @@ let createMessage opts =
msg.ReplyTo.Add (MailboxAddress (opts.Group.Preferences.EmailFromName, opts.Group.Preferences.EmailFromAddress)) msg.ReplyTo.Add (MailboxAddress (opts.Group.Preferences.EmailFromName, opts.Group.Preferences.EmailFromAddress))
msg msg
open MimeKit.Text
/// Create an HTML-format e-mail message /// Create an HTML-format e-mail message
let createHtmlMessage opts = let createHtmlMessage opts =
let bodyText = let bodyText =

View File

@ -79,6 +79,8 @@ let edit reqId : HttpHandler = requireAccess [ User ] >=> fun next ctx -> task {
| Result.Error e -> return! e | Result.Error e -> return! e
} }
open Microsoft.Extensions.Configuration
// GET /prayer-requests/email/[date] // GET /prayer-requests/email/[date]
let email date : HttpHandler = requireAccess [ User ] >=> fun next ctx -> task { let email date : HttpHandler = requireAccess [ User ] >=> fun next ctx -> task {
let s = ctx.Strings let s = ctx.Strings
@ -86,7 +88,7 @@ let email date : HttpHandler = requireAccess [ User ] >=> fun next ctx -> task {
let! list = generateRequestList ctx listDate let! list = generateRequestList ctx listDate
let group = ctx.Session.CurrentGroup.Value let group = ctx.Session.CurrentGroup.Value
let! recipients = Members.forGroup group.Id let! recipients = Members.forGroup group.Id
use! client = Email.getConnection () use! client = Email.getConnection (ctx.GetService<IConfiguration> ())
do! Email.sendEmails do! Email.sendEmails
{ Client = client { Client = client
Recipients = recipients Recipients = recipients

View File

@ -245,6 +245,7 @@ let savePreferences : HttpHandler = requireAccess [ User ] >=> validateCsrf >=>
open Giraffe.ViewEngine open Giraffe.ViewEngine
open PrayerTracker.Views.CommonFunctions open PrayerTracker.Views.CommonFunctions
open Microsoft.Extensions.Configuration
// POST /small-group/announcement/send // POST /small-group/announcement/send
let sendAnnouncement : HttpHandler = requireAccess [ User ] >=> validateCsrf >=> fun next ctx -> task { let sendAnnouncement : HttpHandler = requireAccess [ User ] >=> validateCsrf >=> fun next ctx -> task {
@ -268,7 +269,7 @@ let sendAnnouncement : HttpHandler = requireAccess [ User ] >=> validateCsrf >=>
return users |> List.map (fun u -> { Member.empty with Name = u.Name; Email = u.Email }) return users |> List.map (fun u -> { Member.empty with Name = u.Name; Email = u.Email })
else return! Members.forGroup group.Id else return! Members.forGroup group.Id
} }
use! client = Email.getConnection () use! client = Email.getConnection (ctx.GetService<IConfiguration> ())
do! Email.sendEmails do! Email.sendEmails
{ Client = client { Client = client
Recipients = recipients Recipients = recipients