找回密码邮件发送类

简单的代码发送邮件代码:

 

private void SendEmail()
    {
         MailMessage objMailMessage;
         Attachment objMailAttachment;
         // 创建一个附件对象
        objMailAttachment = new Attachment("d:\\test.txt");//发送邮件的附件
         // 创建邮件消息
         objMailMessage = new MailMessage();
         objMailMessage.From = new MailAddress("chenli3319@gmail.com");//你自己的邮箱地址

         objMailMessage.To.Add("mtl8007@sohu.com");//目的邮件地址俺的QQ邮箱

         objMailMessage.Subject = "邮件发送标题:你好!";//发送邮件的标题

         objMailMessage.Body = "邮件发送标内容:测试一下是否发送成功!";//发送邮件的内容
         objMailMessage.IsBodyHtml = true;
         objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
         objMailMessage.Priority = System.Net.Mail.MailPriority.Normal;
         objMailMessage.Attachments.Add(objMailAttachment);//将附件附加到邮件消息对象中
         //SMTP地址
         SmtpClient smtpClient = new SmtpClient("smtp.gmail.com");//网络上的代理服务器
         smtpClient.EnableSsl = true;
         smtpClient.Credentials = new System.Net.NetworkCredential(objMailMessage.From.Address, "13630264905");//设置发件人身份的信息

         smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

         smtpClient.Host = "smtp." + objMailMessage.From.Host;

         smtpClient.Send(objMailMessage);
    }

  

posted @ 2013-06-19 17:21  double_ed  Views(194)  Comments(0Edit  收藏  举报