2012-03-11 28 views
5
i need solution for this error 

Bu seferde bir hata oluştuğunda yaşıyorum: E-posta Gönderilemedi. SMTP sunucusu güvenli bir bağlantı gerektirir veya istemci kimlik doğrulaması yapılmadı. Sunucu yanıtı: 5.7.0 Önce bir STARTTLS komutu vermeli.asp.net'de smtp kullanarak nasıl posta gönderilir

smtpClient.Credentials = new NetworkCredentials("yourUserName", "yourPassword"); 

Bu mesaj göndermek için kimlik doğrulaması için kullanılan budur: i1sm8651517pbj.70

using System; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.HtmlControls; 
    using System.Net.Mail; 

    public partial class _Default : System.Web.UI.Page 
    { 
     #region "Send email" 
     protected void btnSendmail_Click(object sender, EventArgs e) 
     { 
      // System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0 
      // System.Net.Mail.SmtpClient is the alternate class for this in 2.0 
      SmtpClient smtpClient = new SmtpClient(); 
      MailMessage message = new MailMessage(); 

      try 
      { 
       MailAddress fromAddress = new MailAddress(txtEmail.Text, txtName.Text); 

       // You can specify the host name or ipaddress of your server 
       // Default in IIS will be localhost 
       smtpClient.Host = "smtp.gmail.com"; 

       //Default port will be 25 
       smtpClient.Port = 587; 

       //From address will be given as a MailAddress Object 
       message.From = fromAddress; 

       // To address collection of MailAddress 
       message.To.Add("[email protected]"); 
       message.Subject = "Feedback"; 

       // CC and BCC optional 
       // MailAddressCollection class is used to send the email to various users 
       // You can specify Address as new MailAddress("[email protected]") 
       message.CC.Add("[email protected]"); 
       message.CC.Add("[email protected]"); 

       // You can specify Address directly as string 
       message.Bcc.Add(new MailAddress("[email protected]")); 
       message.Bcc.Add(new MailAddress("[email protected]")); 

       //Body can be Html or text format 
       //Specify true if it is html message 
       message.IsBodyHtml = false; 

       // Message body content 
       message.Body = txtMessage.Text; 

       // Send SMTP mail 
       smtpClient.Send(message); 

       lblStatus.Text = "Email successfully sent."; 
      } 
      catch (Exception ex) 
      { 
       lblStatus.Text = "Send Email Failed.<br>" + ex.Message; 
      } 
     } 
     #endregion 

     #region "Reset" 
     protected void btnReset_Click(object sender, EventArgs e) 
     { 
      txtName.Text = ""; 
      txtMessage.Text = ""; 
      txtEmail.Text = ""; 
     } 
     #endregion 
    } 

cevap

2

Sen SmtpClient.Credentials özelliğini ayarlamak gerekir. Ayrıca SSL etkin olduğundan emin olun gerekebilir:

smtpClient.EnableSsl = true; 

SmtpClient.Credentials Property MSDN Reference

+0

O olmalıdır System.Net.NetworkCredential (s olmadan): Burada

örnek kodudur. – zbarrier

1

Size SSL gerektirir GMail kullanarak bir e-posta göndermek için çalışıyoruz görünüyor.
Bkz. Bu Google reference post. SSL bu şekilde etkinleştirmek web.config Yani

, Alternatif

<system.net> 
    <mailSettings> 
     <smtp deliveryMethod="network"> 
     <network host="smtp.gmail.com" port="587" enableSsl="true" userName="YOURUSERNAME" password="YOURPASSWORD" /> 
     </smtp> 
    </mailSettings> 
    </system.net> 

, bunu programmatically this way ayarlayabilirsiniz:

smtpClient.EnableSsl = true; 
0

EnableSSL özelliğini gmail için gerekli olan true olarak ayarlamayı unuttuğunuzu düşünüyorum.

protected void btnSend_Click(object sender, EventArgs e) 
{ 
    try 
    {    
     MailMessage msg = new MailMessage(); 
     msg.From = new MailAddress(txtFrom.Text);     
     msg.To.Add(new MailAddress(txtTo.Text)); 
     msg.Subject = txtSubject.Text; 
     msg.Body = txtBody.Text;       

     SmtpClient mySmtpClient = new SmtpClient(); 
     System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential(txtFrom.Text,txtPwd.Text); 
     mySmtpClient.Host = "smtp.gmail.com"; 
     mySmtpClient.Port=587; 
     mySmtpClient.EnableSsl = true; 
     mySmtpClient.UseDefaultCredentials = false; 
     mySmtpClient.Credentials = myCredential;     

     mySmtpClient.Send(msg); 
     msg.Dispose(); 
     lberr.Text="Message sent successfully"; 
     clrtxt(); 
    } 
    catch(SmtpException) 
    { 
     lberr.Text="SMTP Error handled"; 
    } 
} 
-1
public void SendMail() 
{ 
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); 
    mail.To.Add(MailTo.Text); 
    mail.From = new MailAddress(MailFrom.Text,"Invoice"); 
    mail.Subject = Subject.Text; 
    mail.Body = Body.Text; 
    mail.IsBodyHtml = true; 



    string FileName = Path.GetFileName(FileUploadAttachments.PostedFile.FileName); 
    Attachment attachment = new Attachment(FileUploadAttachments.PostedFile.InputStream ,FileName); 
    mail.Attachments.Add(attachment);    

    SmtpClient client = new SmtpClient(); 
    client.Credentials = new System.Net.NetworkCredential("[email protected]", "Your_Email_Password"); 
    client.Host = "smtpout.secureserver.net"; 
    client.Port = 80; 
    try 
    { 
     client.Send(mail); 
    } 
    catch (Exception ex) 
    { 
     System.Windows.Forms.MessageBox.Show(ex.Message); 
    } 
} 
+0

GODADDY kullanarak ATTACHMENTS ile gönder e-posta gönder C# Asp.Net –

+0

Cevabınızdaki kodunuza yorum ve açıklamalar ekleyebilirsiniz. – HDJEMAI

+0

Cevabınız Gmail için çalışmaz ve sorudaki hatayı çözmez. –

İlgili konular