Sendmail

From Torben's Wiki
Jump to navigationJump to search

PHP

<?php
$to      = 'test@entorb.net';
$subject = '123 [COVID-19 Alerter] - test';
$message = 'hello';
$headers = 'From: no-reply@entorb.net';
mail($to, $subject, $message, $headers);
?>

Python

import os
SENDMAIL = "/usr/lib/sendmail"
def sendmail(to: str, body: str, subject: str = "[COVID-19 Alerter]", sender: str = 'no-reply@entorb.net'):
    mail = f"To: {to}\nSubject: {subject}\nFrom: {sender}\nContent-Type: text/plain; charset=\"utf-8\"\n\n{body}"
    p = os.popen(f"{SENDMAIL} -t -i", "w")
    p.write(mail)
    # status = p.close()
sendmail(to="test@entorb.net", body="Hier steht der Text Test ÄÖÜß", subject="Test ÄÖÜß")

Perl

$subject = encode( 'UTF-8', $subject );
my $mailprog = '/usr/lib/sendmail';
open( MAIL, "|$mailprog -t" ) || print STDERR "Mail-Error\n";
print MAIL "To: $to\n";
print MAIL "Subject: [Strava] $subject\n";    # =?utf-8?B?
print MAIL "Content-Type: text/plain; charset=\"utf-8\"";
print MAIL "\n$body";
close(MAIL);

Bash

mail.txt

To: test@entorb.net
Subject: sendmail test
From: no-reply@entorb.net

And here goes the e-mail body, test test test..

mail.sh

sendmail -vt < ./mail.txt