Zum Inhalt springen

Python Scripts: Unterschied zwischen den Versionen

Aus Computech CMS Wiki
Reto (Diskussion | Beiträge)
Die Seite wurde neu angelegt: „Um mit python Mails zu versenden folgenden Script anpassen: import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEB…“
 
Reto (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
 
Zeile 1: Zeile 1:
Um mit python Mails zu versenden folgenden Script anpassen:
Um mit python Mails zu versenden folgenden Script anpassen:
  import smtplib
  from email.MIMEMultipart import MIMEMultipart
  from email.MIMEBase import MIMEBase
  from email.MIMEText import MIMEText
  from email import Encoders
  import os


  mail_user = "noreplay@zeberliEDV.ch"
<syntaxhighlight lang="python" line start="1" highlight="5" enclose="div">
  mail_pwd = "qbz8AxEbcjMHzp6i726f"
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os


  def mail(to, subject, text):
mail_user = "noreplay@zeberliEDV.ch"
      msg = MIMEMultipart()
mail_pwd = "qbz8AxEbcjMHzp6i726f"


      msg['From'] = mail_user
def mail(to, subject, text):
      msg['To'] = to
    msg = MIMEMultipart()
      msg['Subject'] = subject


      msg.attach(MIMEText(text))
    msg['From'] = mail_user
      #if you want to send the text as test and attached textfile, uncomment the following line
    msg['To'] = to
      #msg.attach(MIMEText(text))
    msg['Subject'] = subject


      mailServer =smtplib.SMTP("smtp.nine.ch", 587)
    msg.attach(MIMEText(text))
      mailServer.ehlo()
    #if you want to send the text as test and attached textfile, uncomment the following line
      mailServer.starttls()
    #msg.attach(MIMEText(text))
      mailServer.ehlo()
      mailServer.login(mail_user, mail_pwd)
      mailServer.sendmail(mail_user, to, msg.as_string())
      mailServer.close()


  mail("backup@zeberliedv.ch",
    mailServer =smtplib.SMTP("smtp.nine.ch", 587)
      "Datensicherung",
    mailServer.ehlo()
      "Die Datensicherung hat nicht geklappt, bitte kontrollieren")
    mailServer.starttls()
    mailServer.ehlo()
    mailServer.login(mail_user, mail_pwd)
    mailServer.sendmail(mail_user, to, msg.as_string())
    mailServer.close()
 
mail("backup@zeberliedv.ch",
    "Datensicherung",
    "Die Datensicherung hat nicht geklappt, bitte kontrollieren")
</syntaxhighlight>

Aktuelle Version vom 21. Februar 2014, 10:27 Uhr

Um mit python Mails zu versenden folgenden Script anpassen:

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os

mail_user = "noreplay@zeberliEDV.ch"
mail_pwd = "qbz8AxEbcjMHzp6i726f"

def mail(to, subject, text):
    msg = MIMEMultipart()

    msg['From'] = mail_user
    msg['To'] = to
    msg['Subject'] = subject

    msg.attach(MIMEText(text))
    #if you want to send the text as test and attached textfile, uncomment the following line
    #msg.attach(MIMEText(text))

    mailServer =smtplib.SMTP("smtp.nine.ch", 587)
    mailServer.ehlo()
    mailServer.starttls()
    mailServer.ehlo()
    mailServer.login(mail_user, mail_pwd)
    mailServer.sendmail(mail_user, to, msg.as_string())
    mailServer.close()

mail("backup@zeberliedv.ch",
     "Datensicherung",
     "Die Datensicherung hat nicht geklappt, bitte kontrollieren")