This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfrmemailtool.cpp
104 lines (87 loc) · 2.77 KB
/
frmemailtool.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma execution_character_set("utf-8")
#include "frmemailtool.h"
#include "ui_frmemailtool.h"
#include "qfiledialog.h"
#include "qmessagebox.h"
#include "sendemailthread.h"
frmEmailTool::frmEmailTool(QWidget *parent) : QWidget(parent), ui(new Ui::frmEmailTool)
{
ui->setupUi(this);
this->initForm();
}
frmEmailTool::~frmEmailTool()
{
delete ui;
}
void frmEmailTool::initForm()
{
ui->cboxServer->setCurrentIndex(1);
connect(SendEmailThread::Instance(), SIGNAL(receiveEmailResult(QString)),
this, SLOT(receiveEmailResult(QString)));
SendEmailThread::Instance()->start();
}
void frmEmailTool::on_btnSend_clicked()
{
if (!check()) {
return;
}
SendEmailThread::Instance()->setEmailTitle(ui->txtTitle->text());
SendEmailThread::Instance()->setSendEmailAddr(ui->txtSenderAddr->text());
SendEmailThread::Instance()->setSendEmailPwd(ui->txtSenderPwd->text());
SendEmailThread::Instance()->setReceiveEmailAddr(ui->txtReceiverAddr->text());
//设置好上述配置后,以后只要调用Append方法即可发送邮件
SendEmailThread::Instance()->append(ui->txtContent->toHtml(), ui->txtFileName->text());
}
void frmEmailTool::on_btnSelect_clicked()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFiles);
if (dialog.exec()) {
ui->txtFileName->clear();
QStringList files = dialog.selectedFiles();
ui->txtFileName->setText(files.join(";"));
}
}
bool frmEmailTool::check()
{
if (ui->txtSenderAddr->text() == "") {
QMessageBox::critical(this, "错误", "用户名不能为空!");
ui->txtSenderAddr->setFocus();
return false;
}
if (ui->txtSenderPwd->text() == "") {
QMessageBox::critical(this, "错误", "用户密码不能为空!");
ui->txtSenderPwd->setFocus();
return false;
}
if (ui->txtSenderAddr->text() == "") {
QMessageBox::critical(this, "错误", "发件人不能为空!");
ui->txtSenderAddr->setFocus();
return false;
}
if (ui->txtReceiverAddr->text() == "") {
QMessageBox::critical(this, "错误", "收件人不能为空!");
ui->txtReceiverAddr->setFocus();
return false;
}
if (ui->txtTitle->text() == "") {
QMessageBox::critical(this, "错误", "邮件标题不能为空!");
ui->txtTitle->setFocus();
return false;
}
return true;
}
void frmEmailTool::on_cboxServer_currentIndexChanged(int index)
{
if (index == 2) {
ui->cboxPort->setCurrentIndex(1);
ui->ckSSL->setChecked(true);
} else {
ui->cboxPort->setCurrentIndex(0);
ui->ckSSL->setChecked(false);
}
}
void frmEmailTool::receiveEmailResult(QString result)
{
QMessageBox::information(this, "提示", result);
}