找回密碼郵件發送類

簡單的代碼發送郵件代碼:服務器

 

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);
    }
相關文章
相關標籤/搜索