2014-10-09 3 views
0

나는 이것에 대해 해결 질문이 많이 있습니다 미안 알고 있어요,하지만 난 그 솔루션을 사용 작정 시도했지만 내가, 내가 아래 오류가 계속 수없는,이을이다 응용 프로그램을 사용하여 C# .NET을C# .NET을 보내는 메일 오류

Error:The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Linq; 
    using System.Text; 
    using System.Windows.Forms; 
    using System.Net.Mail; 

    namespace WindowsFormsApplication2 
{ 
    public partial class Form1 : Form 
{ 
    bool selecteditems; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); 

     MailAddress from = new MailAddress("[email protected]"); 
     MailAddress to = new MailAddress(textBox1.Text); 



     MailMessage message= new MailMessage(from,to); 
     message.Subject = textBox4.Text; 
     message.Body = richTextBox1.Text; 

     if (textBox2.Text != "") 
     { 
      MailAddress cc = new MailAddress(textBox2.Text); 
      message.CC.Add(cc); 

     } 

     if (textBox3.Text != "") 
     { 
      MailAddress bcc = new MailAddress(textBox3.Text); 
      message.Bcc.Add(bcc); 
     } 
     message.Attachments.Clear(); 
     for (int index = 0; index < listBox1.Items.Count; index++) 
     { 
      Attachment attdata = new Attachment(listBox1.Items[index].ToString()); 
      message.Attachments.Add(attdata); 
     } 
     SmtpServer.Port = 587; 
     SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "password"); 
     SmtpServer.EnableSsl = true; 
     SmtpServer.UseDefaultCredentials = false; 
     SmtpServer.Send(message); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     if (openFileDialog1.ShowDialog() == DialogResult.OK) 
     { 
      string[] files = new String[openFileDialog1.FileNames.Length]; 
      for (int index = 0; index < openFileDialog1.FileNames.Length; index++) 
      { 
       listBox1.Items.Add(openFileDialog1.FileNames[index].ToString()); 
      } 
     } 

    } 

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     selecteditems = true; 
    } 

     private void Form1_Load(object sender, EventArgs e) 
    { 

     } 
    } 
} 
+0

가 "... 내가 ... 많이 노력했다", 나는 그것을 의심 : http://stackoverflow.com/questions/6097333/the-smtp-server-requires-a-secure-connection-or-the- –

+1

그럼 내가이 작업을 가지고 클라이언트 - - - 인증되지 않은, 내가 넣어했다 "SmtpServer.UseDefaultCredentials = 거짓을;" 그것의 정상에 그리고 그것은 일했다! , 모두에게 감사합니다! – user3184290

답변

1
MailMessage mail = new MailMessage(); 
SmtpClient smtp = new SmtpClient(); 

mail.To.Add(textBox1.Text); 
mail.From = new MailAddress("[email protected]"); 
mail.Subject = textBox4.Text; 
mail.IsBodyHtml = false; 
mail.Body = richTextBox1.Text; 
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; 
smtp.Host = "smtp.gmail.com"; 
smtp.Port = 25; 
smtp.Credentials = new NetworkCredential("[email protected]", "samisagoodboy"); 
smtp.EnableSsl = true; 
smtp.Send(mail); 

이보십시오!

+0

SmtpServer.UseDefaultCredentials = false를 추가하면; 그렇다면 모두에게 더 명확 할 것입니다. – lordkain