# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import sys

class Ui_Mail_Send(object):
    def setupUi(self, Mail_Send):
        Mail_Send.setObjectName("Mail_Send")
        Mail_Send.resize(701, 470)

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        Mail_Send.setFont(font)

        self.centralwidget = QtWidgets.QWidget(Mail_Send)
        self.centralwidget.setObjectName("centralwidget")

        self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(20, 50, 661, 361))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")

        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")

        # >> from <<
        self.h_from_mail = QtWidgets.QHBoxLayout()
        self.h_from_mail.setObjectName("h_from_mail")

        self.from_mail_label = QtWidgets.QLabel(self.verticalLayoutWidget)

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.from_mail_label.setFont(font)
        self.from_mail_label.setObjectName("from_mail_label")

        self.h_from_mail.addWidget(self.from_mail_label)

        self.from_mail_text = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        self.from_mail_text.setMaximumSize(QtCore.QSize(16777215, 30))

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.from_mail_text.setFont(font)
        self.from_mail_text.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
        self.from_mail_text.setObjectName("from_mail_text")

        self.h_from_mail.addWidget(self.from_mail_text)

        self.verticalLayout.addLayout(self.h_from_mail)

        # >> from key <<
        self.h_from_mail_key = QtWidgets.QHBoxLayout()
        self.h_from_mail_key.setObjectName("h_from_mail_key")

        self.from_mail_key_label = QtWidgets.QLabel(self.verticalLayoutWidget)

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.from_mail_key_label.setFont(font)
        self.from_mail_key_label.setObjectName("from_mail_key_label")

        self.h_from_mail_key.addWidget(self.from_mail_key_label)

        self.from_mail_key_text = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        self.from_mail_key_text.setMaximumSize(QtCore.QSize(16777215, 30))

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.from_mail_key_text.setFont(font)
        self.from_mail_key_text.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom))
        self.from_mail_key_text.setObjectName("from_mail_key_text")

        self.h_from_mail_key.addWidget(self.from_mail_key_text)

        self.verticalLayout.addLayout(self.h_from_mail_key)

        # >> to <<
        self.h_to_mail = QtWidgets.QHBoxLayout()
        self.h_to_mail.setObjectName("h_to_mail")

        self.to_mail_label = QtWidgets.QLabel(self.verticalLayoutWidget)

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.to_mail_label.setFont(font)
        self.to_mail_label.setObjectName("to_mail_label")
        self.h_to_mail.addWidget(self.to_mail_label)
        self.to_mail_text = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        self.to_mail_text.setMaximumSize(QtCore.QSize(16777215, 30))

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.to_mail_text.setFont(font)
        self.to_mail_text.setObjectName("to_mail_text")

        self.h_to_mail.addWidget(self.to_mail_text)

        self.verticalLayout.addLayout(self.h_to_mail)

        # >> subject <<
        self.h_subject = QtWidgets.QHBoxLayout()
        self.h_subject.setObjectName("h_subject")

        self.subject_label = QtWidgets.QLabel(self.verticalLayoutWidget)

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.subject_label.setFont(font)
        self.subject_label.setObjectName("subject_label")

        self.h_subject.addWidget(self.subject_label)

        self.subject_text = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        self.subject_text.setMaximumSize(QtCore.QSize(16777215, 30))

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.subject_text.setFont(font)
        self.subject_text.setObjectName("subject_text")

        self.h_subject.addWidget(self.subject_text)

        self.verticalLayout.addLayout(self.h_subject)

        # >> mail icerik <<
        self.h_mail_content = QtWidgets.QHBoxLayout()
        self.h_mail_content.setObjectName("h_mail_content")

        self.mail_content_label = QtWidgets.QLabel(self.verticalLayoutWidget)

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.mail_content_label.setFont(font)
        self.mail_content_label.setObjectName("mail_content_label")

        self.h_mail_content.addWidget(self.mail_content_label)

        self.mail_content_text = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        self.mail_content_text.setMaximumSize(QtCore.QSize(16777215, 16777215))

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.mail_content_text.setFont(font)
        self.mail_content_text.setObjectName("mail_content_text_browser")

        self.h_mail_content.addWidget(self.mail_content_text)

        self.verticalLayout.addLayout(self.h_mail_content)

        # >> gönder butonu <<
        self.h_send_pushbutton = QtWidgets.QHBoxLayout()
        self.h_send_pushbutton.setObjectName("h_send_pushbutton")

        self.send_pushbutton_label = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.send_pushbutton_label.setText("")
        self.send_pushbutton_label.setObjectName("send_pushbutton_label")

        self.h_send_pushbutton.addWidget(self.send_pushbutton_label)

        self.send_pushbutton = QtWidgets.QPushButton(self.verticalLayoutWidget)

        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.send_pushbutton.sizePolicy().hasHeightForWidth())

        self.send_pushbutton.setSizePolicy(sizePolicy)
        self.send_pushbutton.setMaximumSize(QtCore.QSize(100, 16777215))

        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)

        self.send_pushbutton.setFont(font)
        self.send_pushbutton.setObjectName("send_pushbutton")

        self.h_send_pushbutton.addWidget(self.send_pushbutton)

        self.verticalLayout.addLayout(self.h_send_pushbutton)

        self.send_pushbutton.clicked.connect(self.sendMail)

        # >> başlık <<
        self.title_label = QtWidgets.QLabel(self.centralwidget)
        self.title_label.setGeometry(QtCore.QRect(250, 10, 191, 31))

        font = QtGui.QFont()
        font.setPointSize(16)

        self.title_label.setFont(font)
        self.title_label.setObjectName("title_label")

        Mail_Send.setCentralWidget(self.centralwidget)

        self.menubar = QtWidgets.QMenuBar(Mail_Send)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 701, 23))
        self.menubar.setObjectName("menubar")

        Mail_Send.setMenuBar(self.menubar)

        self.statusbar = QtWidgets.QStatusBar(Mail_Send)
        self.statusbar.setObjectName("statusbar")

        Mail_Send.setStatusBar(self.statusbar)

        self.retranslateUi(Mail_Send)

        QtCore.QMetaObject.connectSlotsByName(Mail_Send)

    def retranslateUi(self, Mail_Send):
        _translate = QtCore.QCoreApplication.translate

        Mail_Send.setWindowTitle(_translate("Mail_Send", "MAIL GÖNDERME"))

        self.from_mail_label.setText(_translate("Mail_Send", "Gönderen mail adresi :"))

        self.from_mail_key_label.setText(_translate("Mail_Send", "Gönderen mail şifresi :"))

        self.to_mail_label.setText(_translate("Mail_Send", "Gönderilen mail adresi :"))

        self.subject_label.setText(_translate("Mail_Send", "Mail konusu :"))

        self.mail_content_label.setText(_translate("Mail_Send", "Mail içeriği :"))

        self.send_pushbutton.setText(_translate("Mail_Send", "GÖNDER"))

        self.title_label.setText(_translate("Mail_Send", "MAİL GÖNDERME"))

    def sendMail(self):
        message = MIMEMultipart()

        message["From"] = f"{self.from_mail_text}"

        message["To"] = f"{self.to_mail_text}"

        message["Subject"] = f"{self.subject_text}"

        send_mail = f"""
        {self.mail_content_text}
        """

        messageBody = MIMEText(send_mail, "plain")
        message.attach(messageBody)

        userName = str(self.from_mail_text)
        passWord = str(self.from_mail_key_text)

        mail = smtplib.SMTP("smtp.gmail.com", 587)
        mail.ehlo()
        mail.starttls()
        mail.login(userName, passWord)
        mail.sendmail(message["From"], message["To"], message.as_string())
        mail.close()
        self.send_pushbutton_label.setText("Mail başarıyla gönderildi.")




if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Mail_Send = QtWidgets.QMainWindow()
    ui = Ui_Mail_Send()
    ui.setupUi(Mail_Send)
    Mail_Send.show()
    sys.exit(app.exec_())
