def send_mail(self): eml_type = self.in_eml_type.text() eml_file = self.in_eml_template.text() user_group = self.in_recipient_group.text() mail_excel = self.in_recipient_excel.text() annex_file = self.in_annex_file.text() url = self.data_db[5] if self.data_db else 'http://yumail.myvnc.com' try: if self.cb_scheduler.isChecked(): my_time = self.in_scheduler.text()+':00' client = Client() client.send(self.data_smtp[:4], self.data_db[:5], eml_type, eml_file, user_group, mail_excel, annex_file, url, my_time) QMessageBox.information(self, 'Success!', '排程設定成功!', QMessageBox.Ok) else: sm = Smtp(self.data_smtp[0], int(self.data_smtp[1]), self.data_smtp[2], self.data_smtp[3]) if self.data_smtp else Smtp() db = Database(self.data_db[0], int(self.data_db[1]), self.data_db[2], self.data_db[3], self.data_db[4]) if self.data_db else Database() insert_send_mail(eml_type, eml_file, user_group, mail_excel, sm, db, annex=annex_file, url=url) sm.close() db.__disconnect__() QMessageBox.information(self, 'Success!', '信件寄出成功!', QMessageBox.Ok) except: QMessageBox.warning(self, 'Failed!', '信件寄出失敗!', QMessageBox.Ok)
def display_logs(self): self.data_temp_logs = [] self.tbw_logs.setRowCount(0) self.clear_layout(self.right_layout) self.right_layout.addWidget(self.tbw_logs, 1, 3, 11, 8) self.right_layout.addWidget(QLabel('查詢 :'), 0, 3, 1, 1) self.right_layout.addWidget(self.cmb_logs_choice, 0, 4, 1, 2) self.right_layout.addWidget(self.in_logs_data, 0, 6, 1, 3) self.right_layout.addWidget(self.btn_logs_search, 0, 9, 1, 2) try: db = Database(self.data_db[0], int(self.data_db[1]), self.data_db[2], self.data_db[3], self.data_db[4]) if self.data_db[:5] else Database() self.data_logs = db.get_logs() self.data_temp_logs = deepcopy(self.data_logs) if self.data_logs: row_num = len(self.data_logs) col_num = len(self.data_logs[0]) col_lst = list(self.data_logs[0].keys()) self.cmb_logs_choice.clear() self.cmb_logs_choice.addItems(col_lst) self.tbw_logs.setRowCount(row_num) self.tbw_logs.setColumnCount(col_num) self.tbw_logs.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents) self.tbw_logs.setHorizontalHeaderLabels(col_lst) for i in range(row_num): row_data = list(self.data_logs[i].values()) for j in range(col_num): temp_data = row_data[j] item = QTableWidgetItem(str(temp_data)) item.setForeground(QBrush(QColor(144, 182, 240))) self.tbw_logs.setItem(i, j, item) except: QMessageBox.warning(self, 'Failed!', '資料庫連結失敗!', QMessageBox.Ok) else: db.__disconnect__()
if __name__ == '__main__': eml_type, eml_file = '金融', '測資/test.eml' user_group, mail_excel = '智慧資安', '測資/recipients.xlsx' annex_file, date = '測資/風險金融商品比較表.doc', '2020-06-03 11:10:00' smtp_data = [ 'yumail.myvnc.com', '465', '*****@*****.**', 'yucc1234' ] db_data = [ 'yumail.myvnc.com', '3306', 'socialmails', 'socialmails123', 'socialmails' ] mailserver = Smtp(smtp_data[0], int(smtp_data[1]), smtp_data[2], smtp_data[3]) database = Database(db_data[0], int(db_data[1]), db_data[2], db_data[3], db_data[4]) insert_send_mail(eml_type, eml_file, user_group, mail_excel, mailserver, database, annex=annex_file) mailserver.close() database.__disconnect__() # client = Client() # client.send(smtp_data, db_data, eml_type, eml_file, user_group, mail_excel, annex_file, date)