File: smtp_script.py

package info (click to toggle)
sks 1.1.6%2Bgit20210302.c3ba6d5a-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,280 kB
  • sloc: ml: 15,187; ansic: 1,061; sh: 366; makefile: 331; python: 25
file content (33 lines) | stat: -rw-r--r-- 848 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python2

# Simple script for sending out messages via smtp.
# This is an alternative to using sendmail

import smtplib
import os
import sys
import string

msg = [ line for line in sys.stdin ]
msgtext = string.join([line[:-1] for line in msg],sep="\n")

def get_headers(msg):
    i = 0
    headers = {}
    while i < len(msg):
        line = msg[i]
        line = line[:-1]
        if line == "": break
        (field,data) = line.split(":",1)
        field = field.lower().strip()
        data = data.strip()
        if field == "from":
            headers["from"] = data
        elif field == "to":
            headers["to"] = [ addr.strip() for addr in data.split(",") ]
        i = i + 1
    return headers

headers = get_headers(msg)
smtp = smtplib.SMTP("smtp.earthlink.net")
smtp.sendmail(headers["from"],headers["to"],msgtext)