Lỗi gửi Gmail: The message could not be sent to the SMTP server asp.net c#

Thảo luận trong 'Lập trình web Asp.net' bắt đầu bởi seolagi, 30/5/17.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,027
    Đã được thích:
    80
    Điểm thành tích:
    48
    HI mọi người, mình sử dụng chức năng gửi email trong web asp.net, nhưng khi gửi nó báo lỗi : System.Web.HttpException (0x80004005): The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available. Chi tiết lỗi ở dưới đó các bạn.
    Code mình viết gửi email như sau:
    Mã:
     
    mail.Subject = strSubject;
    mail.Body = strBody;
    mail.BodyFormat = MailFormat.Html;
    mail.BodyEncoding = System.Text.Encoding.UTF8;
    mail.Priority = MailPriority.Normal;
    if (strReturn == "")
    {
      SmtpMail.SmtpServer = nội dung....;
      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", "smtp.gmail.com");
      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);
      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "123@gmail.com");
      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123@123");                
      mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
      SmtpMail.Send(mail);
    }
    
    Bị báo lỗi mỗi khi gửi email tới như sau.
    Mã:
    System.Web.HttpException (0x80004005): The message could not be sent to the SMTP server.
    The transport error code was 0x80040217. The server response was not available
    ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
    ---> System.Runtime.InteropServices.COMException: The message could not be sent to the SMTP server.
    The transport error code was 0x80040217. The server response was not available  
    --- End of inner exception stack trace
    --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) 
    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target,
    Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) 
    at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
    at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
    at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message)   at System.Web.Mail.SmtpMail.Send(MailMessage message) 
    at WebCode.Common.SendMail(String strFrom, String strTo, String strCC, String strBCC, String strSubject, String strBody) in E:\C...\Common.cs:line 2788
    
     
    Cảm ơn đã xem bài:

    Lỗi gửi Gmail: The message could not be sent to the SMTP server asp.net c#

  2. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,883
    Đã được thích:
    1,193
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Lỗi này có thể do bạn chưa kích hoạt Gmail cho phép gửi thông qua phần mềm hoặc website ứng dụng đó bạn. Bạn vào link dưới kiểm tra xem đã bật chưa nhé.

    Để kích hoạt bạn truy cập vào link sau : https://www.google.com/settings/security/lesssecureapps

    Sau đó bạn chọn Bật nhé. Xong vào phần mềm hoặc web bạn gửi đã được rồi đó.

    [​IMG]
     
  3. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,027
    Đã được thích:
    80
    Điểm thành tích:
    48
    ah, mình chưa bật chức năng nay, cảm ơn ad hi
     


Chủ để tương tự : Lỗi gửi
Diễn đàn Tiêu đề Date
Lập trình web Asp.net Lỗi: The Type or Namespace name 'MVC' does not exits in the 'System.Web' 18/10/21
Lập trình web Asp.net Lỗi .woff2 404 - File or directory not found trên iis windows 15/10/20
Lập trình web Asp.net Lỗi Save Web.Config Configuration file: Access to the path .tmp is denied 10/10/18
Lập trình web Asp.net Lỗi font chữ khi sử dụng CKEditor.NET formatted in utf-8 html encoding 9/2/18
Lập trình web Asp.net Lỗi Format datetime khi tạo sitemap trong c#, asp.net 16/6/17