partial
class
Form1
:
Form
{
public
Form1(){
InitializeComponent();
}
public
string
line1;
private
void
Form1_Load(
object
sender,
EventArgs
e){
Service_CB.SelectedIndex = 0;
chaqir();
string
Spcmd;
OleDbConnection
cnn =
new
OleDbConnection
(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ line1);
OleDbCommand
cmd =
new
OleDbCommand
();
cmd.Connection = cnn;
cmd.CommandType =
CommandType
.Text;
Spcmd =
"select pochta from dust "
;
cmd.CommandText = Spcmd;
OleDbDataAdapter
da =
new
OleDbDataAdapter
(cmd);
DataTable
dt =
new
DataTable
();
da.Fill(dt);
RecipientEmail_TB.DataSource = dt;
RecipientEmail_TB.DisplayMember =
"pochta"
;
}
private
void
chaqir()
{
string
Spcmd;
OleDbConnection
cnn =
new
OleDbConnection
(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ line1);
OleDbCommand
cmd =
new
OleDbCommand
();
58
cmd.Connection = cnn;
cmd.CommandType =
CommandType
.Text;
Spcmd =
string
.Format(
"select id,mailnomi from foydalan where indeks={0}"
,
Service_CB.SelectedIndex + 1);
cmd.CommandText = Spcmd;
OleDbDataAdapter
da =
new
OleDbDataAdapter
(cmd);
DataTable
dt =
new
DataTable
();
da.Fill(dt);
SenderEmail_TB.DataSource = dt;
SenderEmail_TB.DisplayMember =
"mailnomi"
;
}
private
void
Send_Button_Click(
object
sender,
EventArgs
e){
if
(Service_CB.SelectedIndex == 0){
//localhost
using
(
MailMessage
mm =
new
MailMessage
(SenderName_TB.Text +
" <"
+
SenderEmail_TB.Text +
">"
, RecipientEmail_TB.Text)){
mm.Subject = Subject_TB.Text;
mm.Body = MailText_TB.Text;
mm.IsBodyHtml = IsHTML_CB.Checked;
using
(
SmtpClient
sc =
new
SmtpClient
(
"127.0.0.1"
)){
sc.Send(mm);
}
}
}
else
if
(Service_CB.SelectedIndex == 1){
//Gmail
using
(
MailMessage
mm =
new
MailMessage
(SenderName_TB.Text +
" <"
+
SenderEmail_TB.Text +
">"
, RecipientEmail_TB.Text)){
mm.Subject = Subject_TB.Text;
mm.Body = MailText_TB.Text;
mm.IsBodyHtml = IsHTML_CB.Checked;
using
(
SmtpClient
sc =
new
SmtpClient
(
"smtp.gmail.com"
, 587)){
sc.EnableSsl =
true
;
sc.DeliveryMethod =
SmtpDeliveryMethod
.Network;
sc.UseDefaultCredentials =
false
;
sc.Timeout = 30000;
sc.Credentials =
new
NetworkCredential
(SenderEmail_TB.Text,
AccountPassword_TB.Text);
sc.Send(mm);
}
}
}
else
if
(Service_CB.SelectedIndex == 2){
//Yandex
using
(
MailMessage
mm =
new
MailMessage
(SenderName_TB.Text +
" <"
+
SenderEmail_TB.Text +
">"
, RecipientEmail_TB.Text)){
59
mm.Subject = Subject_TB.Text;
mm.Body = MailText_TB.Text;
mm.IsBodyHtml = IsHTML_CB.Checked;
using
(
SmtpClient
sc =
new
SmtpClient
(
"smtp.yandex.ru"
, 25)){
sc.EnableSsl =
true
;
sc.DeliveryMethod =
SmtpDeliveryMethod
.Network;
sc.UseDefaultCredentials =
false
;
sc.Timeout = 30000;
sc.Credentials =
new
NetworkCredential
(SenderEmail_TB.Text,
AccountPassword_TB.Text);
sc.Send(mm);
}
}
}
else
if
(Service_CB.SelectedIndex == 3){
//Mail.ru
using
(
MailMessage
mm =
new
MailMessage
(SenderName_TB.Text +
" <"
+
SenderEmail_TB.Text +
">"
, RecipientEmail_TB.Text)){
mm.Subject = Subject_TB.Text;
mm.Body = MailText_TB.Text;
mm.IsBodyHtml = IsHTML_CB.Checked;
using
(
SmtpClient
sc =
new
SmtpClient
(
"smtp.mail.ru"
, 25)){
sc.EnableSsl =
true
;
sc.DeliveryMethod =
SmtpDeliveryMethod
.Network;
sc.UseDefaultCredentials =
false
;
sc.Timeout = 30000;
sc.Credentials =
new
NetworkCredential
(SenderEmail_TB.Text,
AccountPassword_TB.Text);
sc.Send(mm);
}
}
}
}
private
void
Service_CB_SelectedIndexChanged(
object
sender,
EventArgs
e){
AccountPassword_TB.Enabled = Service_CB.SelectedIndex != 0;
chaqir();
}
private
void
MailText_TB_TextChanged(
object
sender,
EventArgs
e)
{
}
private
void
IsHTML_CB_CheckedChanged(
object
sender,
EventArgs
e)
60
{
}
private
void
Form1_FormClosing(
object
sender,
FormClosingEventArgs
e)
{
}
private
void
dust_Click(
object
sender,
EventArgs
e)
{
formm.
dustlar
fd =
new
formm.
dustlar
();
fd.path = line1;
fd.Show();
}
private
void
foydalan_Click(
object
sender,
EventArgs
e)
{
formm.
foydalan
df =
new
formm.
foydalan
();
df.path = line1;
df.Show();
}
private
void
AccountPassword_TB_TextChanged(
object
sender,
EventArgs
e)
{
}
}
}
Do'stlaringiz bilan baham: |