richEditBarController 发送邮件
本帖最后由 xuguoju 于 2016-9-23 19:49 编辑/// <summary>
/// 发送邮件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void simpleButton2_Click(object sender, EventArgs e)
{
string fjrtxt = "@qq.com";//发信人
string mmtxt = "这里是验证码"; //密码
string sjrtxt = ;//收信人
string zttxt = ;//主题
string ztname = this.richEditControl1.HtmlText; //正文
string fjtxt = this.textEdit2.Text; //附件
string[] fasong = fjrtxt.Split('@');
string[] fs = fasong.Split('.');
SmtpClient client = new SmtpClient("smtp.qq.com");//设置邮件协议
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network; //通过网络发送到Smtp服务器
client.Credentials = new NetworkCredential(fasong.ToString(), mmtxt); //通过用户名和密码 认证
MailMessage mmsg = new MailMessage(new MailAddress(fjrtxt), new MailAddress(sjrtxt)); //发件人和收件人的邮箱地址
mmsg.Subject = zttxt;//主题
mmsg.Body = ztname; //正文
mmsg.IsBodyHtml = true;
if (textEdit2.Text.Trim() != "")
{
mmsg.Attachments.Add(new Attachment(textEdit2.Text));//增加附件
}
try
{
client.Send(mmsg);
MessageBox.Show("邮件已发成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 得到附件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void simpleButton1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textEdit2.Text = openFileDialog1.FileName;//得到附件的地址
}
}
页:
[1]