Sendmail PyQT

Sendmail PyQT

Questo è un semplice codice python che permette di inviare email col mittente a scelta:

 

 
# -*- coding: utf-8 -*-
 
from PyQt4 import QtCore, QtGui
import smtplib
 
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s
 
class Ui_MailSend(object):
    def setupUi(self, MailSend):
        MailSend.setObjectName(_fromUtf8("MailSend"))
        MailSend.resize(417, 447)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MailSend.sizePolicy().hasHeightForWidth())
        MailSend.setSizePolicy(sizePolicy)
        self.Nome = QtGui.QLineEdit(MailSend)
        self.Nome.setGeometry(QtCore.QRect(130, 30, 261, 20))
        self.Nome.setObjectName(_fromUtf8("Nome"))
        self.Mittente = QtGui.QLineEdit(MailSend)
        self.Mittente.setGeometry(QtCore.QRect(130, 60, 261, 20))
        self.Mittente.setObjectName(_fromUtf8("Mittente"))
        self.Destinatario = QtGui.QLineEdit(MailSend)
        self.Destinatario.setGeometry(QtCore.QRect(130, 90, 261, 20))
        self.Destinatario.setObjectName(_fromUtf8("Destinatario"))
        self.Oggetto = QtGui.QLineEdit(MailSend)
        self.Oggetto.setGeometry(QtCore.QRect(130, 120, 261, 20))
        self.Oggetto.setObjectName(_fromUtf8("Oggetto"))
        self.Provider = QtGui.QComboBox(MailSend)
        self.Provider.setGeometry(QtCore.QRect(130, 150, 111, 22))
        self.Provider.setObjectName(_fromUtf8("Provider"))
        self.Provider.addItem(_fromUtf8(""))
        self.Provider.addItem(_fromUtf8(""))
        self.Provider.addItem(_fromUtf8(""))
        self.Provider.addItem(_fromUtf8(""))
        self.Provider.addItem(_fromUtf8(""))
        self.Provider.addItem(_fromUtf8(""))
        self.Provider.addItem(_fromUtf8(""))
        self.Provider.addItem(_fromUtf8(""))
        self.label = QtGui.QLabel(MailSend)
        self.label.setGeometry(QtCore.QRect(20, 30, 81, 20))
        self.label.setObjectName(_fromUtf8("label"))
        self.label_2 = QtGui.QLabel(MailSend)
        self.label_2.setGeometry(QtCore.QRect(20, 60, 71, 16))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.label_3 = QtGui.QLabel(MailSend)
        self.label_3.setGeometry(QtCore.QRect(20, 90, 101, 16))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_4 = QtGui.QLabel(MailSend)
        self.label_4.setGeometry(QtCore.QRect(20, 120, 91, 16))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.label_5 = QtGui.QLabel(MailSend)
        self.label_5.setGeometry(QtCore.QRect(20, 150, 101, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.Invia = QtGui.QPushButton(MailSend)
        self.Invia.setGeometry(QtCore.QRect(90, 410, 75, 21))
        self.Invia.setObjectName(_fromUtf8("Invia"))
        self.IPSMTP = QtGui.QLineEdit(MailSend)
        self.IPSMTP.setGeometry(QtCore.QRect(130, 180, 261, 20))
        self.IPSMTP.setObjectName(_fromUtf8("IPSMTP"))
        self.label_6 = QtGui.QLabel(MailSend)
        self.label_6.setGeometry(QtCore.QRect(20, 180, 121, 16))
        self.label_6.setObjectName(_fromUtf8("label_6"))
        self.Status = QtGui.QListWidget(MailSend)
        self.Status.setEnabled(False)
        self.Status.setGeometry(QtCore.QRect(242, 410, 121, 20))
        self.Status.setObjectName(_fromUtf8("Status"))
        self.plainTextEdit = QtGui.QPlainTextEdit(MailSend)
        self.plainTextEdit.setGeometry(QtCore.QRect(23, 223, 371, 161))
        self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit"))
        self.retranslateUi(MailSend)
        self.ip = "null"
        QtCore.QMetaObject.connectSlotsByName(MailSend)
        self.Invia.clicked.connect(self.inviala)
        QtCore.QObject.connect(self.Provider, QtCore.SIGNAL("activated(int)"), self.comboselect)
    def retranslateUi(self, MailSend):
        MailSend.setWindowTitle(QtGui.QApplication.translate("MailSend", "MailSend", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(0, QtGui.QApplication.translate("MailSend", "Nessuno", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(1, QtGui.QApplication.translate("MailSend", "Alice", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(2, QtGui.QApplication.translate("MailSend", "Fastweb", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(3, QtGui.QApplication.translate("MailSend", "Libero", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(4, QtGui.QApplication.translate("MailSend", "Telecom", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(5, QtGui.QApplication.translate("MailSend", "Tele2", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(6, QtGui.QApplication.translate("MailSend", "Tiscali", None, QtGui.QApplication.UnicodeUTF8))
        self.Provider.setItemText(7, QtGui.QApplication.translate("MailSend", "Vodafone", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setText(QtGui.QApplication.translate("MailSend", "Nome Mittente:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("MailSend", "Email Mittente:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_3.setText(QtGui.QApplication.translate("MailSend", "Email Destinatario:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_4.setText(QtGui.QApplication.translate("MailSend", "Oggetto dell'Email:", None, QtGui.QApplication.UnicodeUTF8))
        self.label_5.setText(QtGui.QApplication.translate("MailSend", "Provider personale:", None, QtGui.QApplication.UnicodeUTF8))
        self.Invia.setText(QtGui.QApplication.translate("MailSend", "Invia", None, QtGui.QApplication.UnicodeUTF8))
        self.label_6.setText(QtGui.QApplication.translate("MailSend", "IP Provider personale:", None, QtGui.QApplication.UnicodeUTF8))
 
    def comboselect(self, index):
        if index == 0:
           self.ip = "null"
        elif index == 1:
           self.ip = "out.alice.it"
        elif index == 2:
           self.ip = "smtp.fastweb.it"
        elif index == 3:
           self.ip = "smtp.libero.it"
        elif index == 4:
           self.ip = "mail.tin.it"
        elif index == 5:
           self.ip = "smtp.tele2.it"
        elif index == 6:
           self.ip = "smtp.tiscali.it"
        elif index == 7:
           self.ip = "smtpmail.vodafone.it"
 
    def inviala(self):
        self.Status.clear()
        if self.ip == "null":
           self.ip = str(self.IPSMTP.text())
        self.mit = str(self.Mittente.text())
        self.nom = str(self.Nome.text())
        self.dest = str(self.Destinatario.text())
        self.dst = [self.dest]
        self.ogt = str(self.Oggetto.text())
        self.mss = self.plainTextEdit.toPlainText()
        self.p = 25
        message = """From: %s <%s>rnTo: %srnSubject: %srnrn%s""" % (self.nom, self.mit, ", ".join(self.dst), self.ogt, self.mss)
        try:
           server = smtplib.SMTP(self.ip)
           server.sendmail(self.mit, self.dst, message)
           server.quit()
           item = QtGui.QListWidgetItem("Email Inviata")
           self.Status.addItem(item)
        except:
           item = QtGui.QListWidgetItem("Impossibile Inviare")
           self.Status.addItem(item)
if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MailSend = QtGui.QWidget()
    ui = Ui_MailSend()
    ui.setupUi(MailSend)
    MailSend.show()
    sys.exit(app.exec_())

Clicca qui per scaricare: Download

 

Se invece volete scaricare l’eseguibile clickate qui: Download

 

Anteprima:

Anteprima 267x300 Sendmail PyQT

2 Comments

Add a Comment

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *