Send mails in background via SMTP (macOS)

Hi!

I wrote a backup program in Swift which is used for several servers. It does send an email each day about the backup status. Currently I use /usr/bin/mail because it works well with via postfix configuration.

Now I need to add an attachment (an image about the access statistics) and this is not possible using the mail command.

I looked at the docs and I found

NSSharingService(named: NSSharingService.Name.composeEmail)

but it does just create a mail which is opened in Mail.app.

Is there really no OS provided way to send an SMTP mail without any user interaction? I don't want to implement a 3rd party SMTP-Library.

TIA,

GreatOm

Answered by Great_Om in 691200022

Meanwhile I got it working. Now I use SwiftSMTP which works well in background. See “swift-smtp/Sources/SwiftSMTPCLI/main.swift“ for sample code how to use it.

If you can use it, there are Python scripts around (search for write-mime-multipart,; can't link to some related SO info here) that generate MIME files, and you can then send that file.

The mpack tool is another potential option.

MIME itself (rfc2045) isn't particularly difficult to construct directly.

Hedwig is no solution for me. It is outdated and works not with Swift 5. Swift SMTP package is also useless for me because it does implement a special handling on macOS which does prevent the usage of self signed snakeoil certificates. I don't want to get an official certificate for my in-house server because the cert is just used for TLS-encryption, which works well on Linux or via postfix on macOS.

So I have currently no solution for this problem.

Accepted Answer

Meanwhile I got it working. Now I use SwiftSMTP which works well in background. See “swift-smtp/Sources/SwiftSMTPCLI/main.swift“ for sample code how to use it.

Send mails in background via SMTP (macOS)
 
 
Q