2016-05-27 2 views
0

私は電子メールを送信するためにgoogle smtpを使用しています。コードは私のローカルマシンで正しく動作します。しかし、プロダクションサーバーでは、私はSendEmailとしてエラーメッセージを受け取っています。SMTPサーバーには安全な接続が必要です。あるいは、クライアントは認証されていません。サーバーの応答は、5.5.1認証が必要でした。詳細はこちらAsp.netSendEmail SMTPサーバーが安全な接続を必要としているか、クライアントが認証されていません

私はこれを試しています。 client.UseDefaultCredentials = true; falseに設定しても機能しません。

答えて

0

は、サーバの応答をグーグル

  MailMessage oMail = new MailMessage(); 
      SmtpClient smtpClient = new SmtpClient(); 
      string FromMailID = "[email protected]"; 
      string UserName = "GmailUsername"; 
      string Password = "GmailPassword"; 

      MailAddress fromAddress = new MailAddress(FromMailID); 
      if (FilePath != "")//If attached file otherwise comment 
      { 
       Attachment PDFfile = new Attachment(FilePath); 
       oMail.Attachments.Add(PDFfile); 
      } 
      oMail.From = fromAddress; 
      oMail.To.Add(ToMailID); 
      oMail.Subject = Subject; 
      oMail.IsBodyHtml = true; 
      oMail.Body = Mailcontent.ToString(); 
      smtpClient.Host = "smtp.gmail.com"; // We use gmail as our smtp client 
      smtpClient.Port = 25;//localhost 
      smtpClient.UseDefaultCredentials = false; 
      smtpClient.EnableSsl = true; 
      smtpClient.UseDefaultCredentials = true; 
      smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; 
      smtpClient.Credentials = new System.Net.NetworkCredential(UserName, Password); 

      smtpClient.Send(oMail); 
+0

により、送信メールのためにこのコードをして試してみてください。5.5.1認証が必要です。 Gmailのセキュリティを確認する リモートサーバーの場合は、サーバーからGmailアカウントにログインする –

関連する問題