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
open MailKit.Net.Smtp
open MailKit.Security
open Microsoft.Extensions.Localization
open MimeKit
open MimeKit.Text
open PrayerTracker.Entities
/// Parameters required to send an e-mail
@ -35,11 +33,13 @@ type EmailOptions =
/// The e-mail address from which e-mail is sent
let private fromAddress = "prayer@bitbadger.solutions"
open MailKit.Security
open Microsoft.Extensions.Configuration
/// Get an SMTP client connection
// FIXME: make host configurable
let getConnection () = task {
let getConnection (cfg : IConfiguration) = task {
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
}
@ -51,6 +51,8 @@ let createMessage opts =
msg.ReplyTo.Add (MailboxAddress (opts.Group.Preferences.EmailFromName, opts.Group.Preferences.EmailFromAddress))
msg
open MimeKit.Text
/// Create an HTML-format e-mail message
let createHtmlMessage opts =
let bodyText =

View File

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

View File

@ -245,6 +245,7 @@ let savePreferences : HttpHandler = requireAccess [ User ] >=> validateCsrf >=>
open Giraffe.ViewEngine
open PrayerTracker.Views.CommonFunctions
open Microsoft.Extensions.Configuration
// POST /small-group/announcement/send
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 })
else return! Members.forGroup group.Id
}
use! client = Email.getConnection ()
use! client = Email.getConnection (ctx.GetService<IConfiguration> ())
do! Email.sendEmails
{ Client = client
Recipients = recipients