62,268
社区成员
发帖
与我相关
我的任务
分享
#region[发送邮件]
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void bt_send_Click(object sender, EventArgs e)
{
string attachmenturl = up_MailAttachment.PostedFile.FileName.Replace("\\", "\\\\");
//创建一个附件对象
MailAttachment objmailattachment = new MailAttachment(attachmenturl);
//创建邮件内容对象
MailMessage objmailmessage = new MailMessage();
objmailmessage.To = txt_to.Text.ToString();//目的邮件地址
objmailmessage.From = "sglcj@126.com";//源邮件地址
objmailmessage.Subject = "test send Email";//邮件主题
objmailmessage.Body = "test send Email,success or Failure";//邮件正文
objmailmessage.Attachments.Add(objmailattachment);//将附件添加到邮件中
//基本权限
objmailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//用户名
objmailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sglcj");//sglcj为发信邮箱账号
//密码
objmailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "456456");//456456发信邮箱密码
//
SmtpMail.SmtpServer = "smtp.126.com";
//SmtpMail.SmtpServer = "127.0.0.1";
SmtpMail.Send(objmailmessage);
}
#endregion