2013-06-01 3 views
0

문제가 있습니다. .txt 목록에서 주소로 전자 메일을 보낼 수있는 프로그램을 코딩했습니다. 그것은 작동합니다 (저는 독일에 있습니다).하지만 다른 사람들에게는 (다른 나라에서는) 작동하지 않습니다. Gmail을 통해 이메일을 보내는 경우에만 작동합니다. 어떤 도움이 필요합니까? 한 가지 이유를 들어,Gmail을 통해서만 Hotmail을 통해 이메일을 보낼 수 없습니다.

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void cmdDistribute_Click(object sender, EventArgs e) 
    { 
     FileStream fs; 
     StreamReader sr; 

     if (Receiverlist.Text == "") 
     { 
      MessageBox.Show("Please type in the path of the list with the receiver! (.txt)", "ERROR : CANT FIND RECEIVERLIST!", MessageBoxButtons.OK, MessageBoxIcon.Error); 
      return; 
     } 

     fs = new FileStream(Receiverlist.Text, FileMode.Open); 
     sr = new StreamReader(fs); 

     string zeile; 

     if (senderID.Text == "") 
     { 
      MessageBox.Show("Please type in your login information!", "ERROR : NO EMAIL ADDRESS!"); 
      fs.Close(); 
      return; 
     } 

     else if (SenderPassword.Text == "") 
     { 
      MessageBox.Show("Please type in your login information!", "ERROR : NO PASSWORD!"); 
      fs.Close(); 
      return; 
     } 

     MessageBox.Show("While sending the emails this programm won´t response till it has send \nall emails! This could take a while, so please be patient...", "ALERT", MessageBoxButtons.OK, MessageBoxIcon.Warning); 

     string mailProvider = ""; 
     int port = 0; 

     try 
     { 
      if (ProviderGmail.Checked) 
      { 
       mailProvider = "smtp.gmail.com"; 
       port = 587; 
      } 
      else if (providerHotmail.Checked) 
      { 
       mailProvider = "smtp.live.com"; 
       port = 587; 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Can´t connect to the GMail/Hotmail server. \n Please contact TheFlash on skype!", "ERROR : SMTPSERVER", MessageBoxButtons.OK, MessageBoxIcon.Error); 
      fs.Close(); 
      return; 
     } 

     if (EmailSubject.Text == "") 
     { 
      MessageBox.Show("Please type in the subject of the email!.", "ERROR : EMPTY SUBJECT", MessageBoxButtons.OK, MessageBoxIcon.Error); 
      fs.Close(); 
      return; 
     } 

     int n = 1; 

     while (sr.Peek() != -1) 
     { 
      zeile = sr.ReadLine(); 

      try 
      { 

       System.Net.Mail.MailAddress DistributorMail = new System.Net.Mail.MailAddress(senderID.Text); 
       System.Net.Mail.MailAddress Receiver = new System.Net.Mail.MailAddress(zeile); 
       System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage(DistributorMail, Receiver); 
       email.Subject = EmailSubject.Text; 
       email.Body = EmailBody.Text; 

       System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(mailProvider,port); 
       client.EnableSsl = true; 
       client.UseDefaultCredentials = false; 
       client.Credentials = new System.Net.NetworkCredential(senderID.Text, SenderPassword.Text); 

       if (checkBox1.Checked) 
       { 
        if (EmailAttachment.Text == "") 
        { 
         MessageBox.Show("Please type in the path of your attachment!.", "ERROR : EMPTY ATTACHMENT PATH", MessageBoxButtons.OK, MessageBoxIcon.Error); 
         fs.Close(); 
         return; 
        } 
        else 
        { 
         MessageBox.Show("If you add an attachment to your mail, it will take longer to send it!", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
         email.Attachments.Add(new System.Net.Mail.Attachment(EmailAttachment.Text)); 
        } 
       } 
       else 
       { 
        EmailAttachment.Enabled = false; 
       } 

       try 
       { 
        client.Send(email); 
        label9.Text = "Emails sent : " + n; 
        n = n + 1; 

        if (sr.Peek() == -1) 
         MessageBox.Show("Finished!", "TheFlash´s Email Distributor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
       } 
       catch (Exception Ex) 
       { 
        label9.Text = "Couldn´t send the emails!"; 
        fs.Close(); 
        return; 
       } 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show("This is not an valid email address.", "ERROR : WRONG EMAIL FORMAT", MessageBoxButtons.OK, MessageBoxIcon.Error); 
       fs.Close(); 
       return; 
      } 

     } 
     fs.Close(); 
     return; 

    } 

    private void cmdExit_Click(object sender, EventArgs e) 
    { 
     Close(); 
    } 

    private void cmdAbout_Click(object sender, EventArgs e) 
    { 
     new AboutBox1().Show(); 
    } 
} 
+0

당신은 TLS하거나 기본 SSL과 연결 있습니까 ? –

+0

제목을 편집 한 이유를 이해하려면 [이 대답] (http://meta.stackexchange.com/a/130208/213671)을 읽으십시오. – gunr2171

+0

@MikePrecup은 기본 SSL로 연결합니다. 코드 맨에서 ... – iAmFastAndYou

답변

0

확인하거나 사용자 것 같아 또 다른 자신의 Hotmail 계정에서 잠겨있을 수도 있습니다 : 여기

는 코드입니다. 따라서 그들은 정상적인 웹 페이지를 통해 로그인을 시도하고 퍼즐을 풀어 잠금을 해제하도록 요청할 수 있습니다. 이에 대한 자세한 정보를 원하시면 다음을 참조하십시오

Why am I repeatedly locked out of my Hotmail account, and what can I do about it?

나는이 문제를 코딩 할 수 있는지 확실하지 않습니다. 당신이 여기 볼 수 과거의 문제가 있었다 :

SMTP Client Sending error in C# app

Send email via Hotmail to gmail

항목 :

Sending Email From C# Via Hotmail/Outlook/Windows Live

facing issues while sending mail using smtp.live.com in c#

+0

감사합니다. 문제 일 수 있습니다. 두 분 모두 문제가있어서 혼란 스러웠습니다./그리고 나는 잠을 자지 않고 2 일 이상 노력하여 그 하하 하임을 그렇게 바보처럼 만들었습니다. ^^ 다시 한번 감사드립니다. 좋은 하루 되세요! – iAmFastAndYou

+0

반갑습니다. 어리 석을 느끼지 마세요 :) 예외를 삼키지 않는 것이 가장 좋습니다. 문제를 진단/해결할 때 친구가 될 것이기 때문입니다. 너도 좋은 하루 되셨다. – davmos

+0

바보 같은 기분이 들지 않도록하십시오. 나도이 문제를 겪었는데, 그 이유는 대답의 섹션을 참조하십시오. 놓치기 쉽습니다. –