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

Accepted Reply

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.

Replies

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.

  • Thanks for your help. I thought already about manual MIME but I guess that I will exceed SHELL limits using the mail command with a large message body.

    Now I look for 3rd party SMTP solution. Today I will try Hedwig.

    Too bad that there is no direct OS API.

Add a Comment

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.

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.