Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7dc43cb
Add more logging and error handling for SMTP
supersven Oct 28, 2022
e78deea
Catch in ensureSMTPConnectionTimeout
supersven Oct 28, 2022
040f64e
Improve logging
supersven Oct 28, 2022
93ae798
Remove unnecessary do-s
supersven Oct 28, 2022
2b0cb7d
Add type signatures
supersven Oct 28, 2022
6fe26ee
Simplify expressions
supersven Oct 28, 2022
0185d32
Guard closing of the test connection
supersven Oct 28, 2022
90c6dcc
Better log prefix strings
supersven Oct 31, 2022
7f9603e
Add postie to brig integration test dependencies
supersven Nov 2, 2022
1006f8a
Add first SMTP test
supersven Nov 2, 2022
7d832fe
Adjust log strings
supersven Nov 2, 2022
1a22e54
Good case: Receive mail via SMTP
supersven Nov 2, 2022
9eaa8ff
Ensure Subject is sent/received
supersven Nov 2, 2022
178ec4e
Add TODO
supersven Nov 2, 2022
6fd873e
Test failed SMTP transaction
supersven Nov 2, 2022
9840f38
Formatting...
supersven Nov 2, 2022
e22ba2c
Add more tests
supersven Nov 3, 2022
33a0f86
Better test description
supersven Nov 3, 2022
2c062d2
Simplify test setup: Get rid on IO
supersven Nov 3, 2022
67e4f7d
More on tests
supersven Nov 3, 2022
2a2cdac
Flush log before error handling
supersven Nov 3, 2022
719a4c7
Resolve TODOs
supersven Nov 3, 2022
4c018b0
Add changelog
supersven Nov 3, 2022
bde1959
Use random port for SMTP server
supersven Nov 4, 2022
efa220e
Reduce test setup duplication
supersven Nov 4, 2022
7e43aa2
Re-order functions
supersven Nov 4, 2022
413911c
Ensure that test mail server ports aren't priviledged and not already…
supersven Nov 4, 2022
64a2d7e
Final touches to log/error messages
supersven Nov 4, 2022
6b2e1c0
Add missing Nix dependencies
supersven Nov 11, 2022
adf599d
Stricter version definition for postie
supersven Nov 21, 2022
9ddd32b
Use Log.field to combine log items
supersven Nov 21, 2022
33af675
Add haddock
supersven Nov 21, 2022
b37f3fa
Simplify: Get rid of Either
supersven Nov 22, 2022
6842b15
Cleanup
supersven Nov 22, 2022
f509136
Fix typo
supersven Nov 22, 2022
40864e5
Update services/brig/src/Brig/SMTP.hs
supersven Nov 23, 2022
d5d095a
Update services/brig/src/Brig/SMTP.hs
supersven Nov 23, 2022
869a934
Reduce duplication in logging
supersven Nov 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2-features/smtp-logging
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add more logs to SMTP mail sending. Ensure that logs are written before the application fails due to SMTP misconfiguration.
2 changes: 2 additions & 0 deletions libs/types-common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
, lens-datetime
, lib
, mime
, network
, optparse-applicative
, pem
, protobuf
Expand Down Expand Up @@ -91,6 +92,7 @@ mkDerivation {
lens
lens-datetime
mime
network
optparse-applicative
pem
protobuf
Expand Down
6 changes: 5 additions & 1 deletion libs/types-common/src/Wire/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ import GHC.Generics (Rep)
import Generic.Random (listOf', (:+) ((:+)))
import qualified Generic.Random as Generic
import Imports
import Network.Socket (PortNumber)
import Test.QuickCheck.Arbitrary (Arbitrary (arbitrary))
import qualified Test.QuickCheck.Arbitrary as QC
import Test.QuickCheck.Gen (Gen (MkGen))
import Test.QuickCheck.Gen (Gen (MkGen), chooseBoundedIntegral)
import Test.QuickCheck.Instances ()
import Test.QuickCheck.Random

Expand Down Expand Up @@ -120,3 +121,6 @@ generateExample :: Arbitrary a => a
generateExample =
let (MkGen f) = arbitrary
in f (mkQCGen 42) 42

instance Arbitrary PortNumber where
arbitrary = chooseBoundedIntegral (minBound :: PortNumber, maxBound :: PortNumber)
1 change: 1 addition & 0 deletions libs/types-common/types-common.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ library
, lens >=4.10
, lens-datetime >=0.3
, mime >=0.4.0.2
, network
, optparse-applicative >=0.10
, pem
, protobuf >=0.2
Expand Down
8 changes: 8 additions & 0 deletions nix/haskell-pins.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ let
tasty-hunit = "hunit";
};
};
# This can be removed once postie 0.6.0.3 (or later) is in nixpkgs
postie = {
src = fetchgit {
url = "https://github.com/alexbiehl/postie.git";
rev = "c92702386f760fcaa65cd052dc8114889c001e3f";
sha256 = "sha256-yiw6hg3guRWS6CVdrUY8wyIDxoqfGjIVMrEtP+Fys0Y=";
};
};
};
hackagePins = {
kind-generics = {
Expand Down
3 changes: 3 additions & 0 deletions nix/manual-overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ hself: hsuper: {

# Make hoogle static to reduce size of the hoogle image
hoogle = hlib.justStaticExecutables hsuper.hoogle;

# Postie has been fixed upstream (master)
postie = hlib.markUnbroken (hlib.doJailbreak hsuper.postie);
}
7 changes: 7 additions & 0 deletions services/brig/brig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ library
, text >=0.11
, text-icu-translit >=0.1
, time >=1.1
, time-out
, time-units
, tinylog >=0.10
, transformers >=0.3
, types-common >=0.16
Expand Down Expand Up @@ -463,6 +465,7 @@ executable brig-integration
Federation.Util
Index.Create
Main
SMTP
Util
Util.AWS

Expand Down Expand Up @@ -552,13 +555,16 @@ executable brig-integration
, lens-aeson
, metrics-wai
, mime >=0.4
, mime-mail
, MonadRandom >=0.5
, mtl
, network
, optparse-applicative
, pem
, pipes
, polysemy
, polysemy-wire-zoo
, postie >=0.6.0.3
, process
, proto-lens
, QuickCheck
Expand All @@ -579,6 +585,7 @@ executable brig-integration
, temporary >=1.2.1
, text
, time >=1.5
, time-units
, tinylog
, transformers
, types-common >=0.3
Expand Down
10 changes: 10 additions & 0 deletions services/brig/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@
, network-conduit-tls
, optparse-applicative
, pem
, pipes
, polysemy
, polysemy-plugin
, polysemy-wire-zoo
, postie
, process
, proto-lens
, QuickCheck
Expand Down Expand Up @@ -130,6 +132,8 @@
, text
, text-icu-translit
, time
, time-out
, time-units
, tinylog
, transformers
, types-common
Expand Down Expand Up @@ -267,6 +271,8 @@ mkDerivation {
text
text-icu-translit
time
time-out
time-units
tinylog
transformers
types-common
Expand Down Expand Up @@ -329,13 +335,16 @@ mkDerivation {
lens-aeson
metrics-wai
mime
mime-mail
MonadRandom
mtl
network
optparse-applicative
pem
pipes
polysemy
polysemy-wire-zoo
postie
process
proto-lens
QuickCheck
Expand All @@ -356,6 +365,7 @@ mkDerivation {
temporary
text
time
time-units
tinylog
transformers
types-common
Expand Down
7 changes: 4 additions & 3 deletions services/brig/src/Brig/Email.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@ module Brig.Email
where

import qualified Brig.AWS as AWS
import Brig.App (Env, awsEnv, smtpEnv)
import Brig.App (Env, applog, awsEnv, smtpEnv)
import qualified Brig.SMTP as SMTP
import Control.Lens (view)
import Control.Monad.Catch
import qualified Data.Text as Text
import Imports
import Network.Mail.Mime
import Wire.API.User

-------------------------------------------------------------------------------
sendMail :: (MonadIO m, MonadReader Env m) => Mail -> m ()
sendMail :: (MonadIO m, MonadCatch m, MonadReader Env m) => Mail -> m ()
sendMail m =
view smtpEnv >>= \case
Just smtp -> SMTP.sendMail smtp m
Just smtp -> view applog >>= \logger -> SMTP.sendMail logger smtp m
Nothing -> view awsEnv >>= \e -> AWS.execute e $ AWS.sendMail m

-------------------------------------------------------------------------------
Expand Down
Loading