我已经开始使用 Windows 表单来创建一个小应用程序,在该应用程序中,用户能够从他们的 gmail 帐户发送电子邮件,当用户在我的登录表单(FORM 1)中输入正确的登录凭据但如果他输入错误时,我可以发送邮件登录表单(表单 1)中的凭据,它进入我的邮件(表单 2)并显示错误,所以我想检查 Gmail 登录凭据..帮助我使用代码...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
namespace first
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Form1 a = new Form1();
this.Hide();
a.ShowDialog();
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.Credentials = new NetworkCredential(Form3.tb.Text, Form3.tb1.Text);
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(To.Text));
msg.From = new MailAddress(From.Text);
msg.Subject = Sub.Text;
msg.Body = Body.Text;
client.EnableSsl = true; //for security in gmail,https kind of
client.Send(msg);
try
{
MessageBox.Show("Mail sent successfully", "Praveen Mail");
}
catch (Exception ex)
{
MessageBox.Show("Mail Sending Failed Due to" + ex.Message, "Praveen Mail");
}
}
}
}