2013-10-09 216 views
1

我基本上使用Microsoft Visual Studio在C#中發送一個海量電子郵件發件人,它的想法是它使用真正的電子郵件帳戶通過SMTP發送電子郵件,以便它們不被標記爲垃圾郵件,但我保留得到的錯誤:URI格式不支持

URI formats are not supported. 

基本上下面的代碼從我的網站檢索電子郵件帳戶列表,但引發上述錯誤。

String[] saUsernames = File.ReadAllLines(@"http://mywebsite.com/test/accounts.txt"); 

我試着加載文件在本地工作得很好,所以我無法弄清楚是什麼問題,任何人有任何想法,我很好,真正困惑

編輯:繼承人的全腳本別的東西可能會導致錯誤,我已經刪除了一些鏈接到我的網站,如等在發展一個項目,我不想放棄許多線索

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; 
using System.Net.Mail; 
using System.Threading; 
using System.IO; 

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

     int iTimeOutValue = 100; 
     int iSentAmount = 0; 
     SmtpClient client = new SmtpClient(); 
     MailMessage mail = new MailMessage(); 
     String[] saUsernames = File.ReadAllLines(@"http://example.com/accounts.txt"); 
     WebClient wcUpdates = new WebClient(); 
     string sMasterPassword = "testpassword"; 
     string sLastUsername = ""; 
     int iTimeOutWebRequest = 0; 

     private void btnClick(object sender, EventArgs e) 
     { 
      Button btnCurrent = ((Button)sender); 
      if (btnCurrent.Tag.ToString() == "SendMail") 
      { 
       prbSentStatus.Maximum = ((int)nudAmount.Value * saUsernames.Length); 
       Thread tStart = new Thread(SendMail); 
       tStart.Start(); 
      } 
      else if (btnCurrent.Tag.ToString() == "AddAccount") 
      { 
       AddNewAccount(); 
      } 
      else if (btnCurrent.Tag.ToString() == "Update") 
      { 
       try 
       { 
        if (wcUpdates.DownloadString(@"http://example.com/version.txt") != "1.0.0") 
        { 
         if (dlgSaveUpdate.ShowDialog() == DialogResult.OK) 
         { 
          wcUpdates.DownloadFile(@"http://example.com/new.exe", dlgSaveUpdate.FileName); 
         } 
        } 
        else 
        { 
         MessageBox.Show("Your version is up to date!", "Information!"); 
        } 
       } 
       catch 
       { 

       } 
      } 
     } 

     private void SendMail() 
     { 
      int iToSend = Convert.ToInt32(nudAmount.Value); 
      for (int i = 0; i < saUsernames.Length; i++) 
      { 
       GrabMailDetails(i); 
       client.Credentials = new NetworkCredential(saUsernames[i], sMasterPassword); 
       if (saUsernames[i] != sLastUsername) 
       { 
        if (saUsernames[i].EndsWith("@yahoo.com")) 
        { 
         client.Host = "smtp.mail.yahoo.com"; 
         client.Port = 587; 
         client.EnableSsl = false; 
        } 
        else if (saUsernames[i].EndsWith("@gmail.com")) 
        { 
         client.Host = "smtp.gmail.com"; 
         client.Port = 25; 
         client.EnableSsl = true; 
        } 
        else if (saUsernames[i].EndsWith("@hotmail.co.uk")) 
        { 
         client.Host = "smtp.live.com"; 
         client.Port = 587; 
         client.EnableSsl = true; 
        } 
        else if (saUsernames[i].EndsWith("@outlook.com")) 
        { 
         client.Host = "smtp.live.com"; 
         client.Port = 587; 
         client.EnableSsl = true; 
        } 
        else if (saUsernames[i].EndsWith("@hotmail.com")) 
        { 
         client.Host = "smtp.live.com"; 
         client.Port = 587; 
         client.EnableSsl = true; 
        } 
        else if (saUsernames[i].EndsWith("@aol.co.uk")) 
        { 
         client.Host = "smtp.aol.com"; 
         client.Port = 587; 
         client.EnableSsl = true; 
        } 
        else if (saUsernames[i].EndsWith("@aol.com")) 
        { 
         client.Host = "smtp.aol.com"; 
         client.Port = 587; 
         client.EnableSsl = true; 
        } 
       } 
       else 
       { 

       } 
       sLastUsername = saUsernames[i]; 

       for (int x = 0; x < iToSend; x++) 
       { 
        try 
        { 
         client.Send(mail); 
         iSentAmount++; 
        } 
        catch 
        { 
         MessageBox.Show("Maximum emails today sent from this SMTP server has been reached.\nAccount name: " + sLastUsername, "Error!"); 
         goto JMP; 
        } 
       } 
       JMP: ; 
      } 

     } 

     private void GrabMailDetails(int count) 
     { 
      try 
      { 
       mail = new MailMessage(); 
       mail.Body = tbBody.Text; 
       mail.Subject = tbSubject.Text; 
       mail.From = new MailAddress(saUsernames[count]); 
       mail.To.Add(tbTarget.Text); 
       { 
           } 
       if (rbHigh.Checked) 
       { 
        mail.Priority = MailPriority.High; 
       } 
       else if (rbLow.Checked) 
       { 
        mail.Priority = MailPriority.Low; 
       } 
       else if (rbNorm.Checked) 
       { 
        mail.Priority = MailPriority.Normal; 
       } 
      } 
      catch 
      { 

      } 
     } 

     private void AddNewAccount() 
     { 
      String[] saCurrentAccounts = File.ReadAllLines(@"Accounts.txt"); 
      string sAddNewAccount = ""; 
      for (int i = 0; i < saCurrentAccounts.Length; i++) 
      { 
       sAddNewAccount += saCurrentAccounts[i] + Environment.NewLine; 
      } 

     } 

     private void timeUpdate_Tick(object sender, EventArgs e) 
     { 
      prbSentStatus.Value = iSentAmount; 
      lblEmailSentCount.Text = "Emails Sent: " + iSentAmount; 
      iTimeOutWebRequest++; 
      if (iTimeOutWebRequest == iTimeOutValue) 
      { 

      } 
     } 


     private void Form1_Load(object sender, EventArgs e) 
     { 
      timeUpdate.Start(); 
      lblMultiple.Text = "x " + saUsernames.Length; 
      this.Text = "test - " + Environment.UserName; 
     } 

     private void pictureBox1_Click(object sender, EventArgs e) 
     { 

     } 

     private void button2_Click(object sender, EventArgs e) 
     { 
      if (wcUpdates.DownloadString(@"update.com/version") != "1.0.0") 
        { 
         if (dlgSaveUpdate.ShowDialog() == DialogResult.OK) 
         { 
          MessageBox.Show("Updating LulzBomber. Please wait a few minutes", "Information!"); 
          wcUpdates.DownloadFile(@"update.com/version", dlgSaveUpdate.FileName); 
         } 
        } 
        else 
        { 
         MessageBox.Show("Your version is up to date!", "Information!"); 
        } 
      } 

     private void button3_Click(object sender, EventArgs e) 
     { 
      MessageBox.Show("Created by ***", "About"); 
     } 

     } 
    } 
+0

隨着越來越多的崇高目標這樣的示例代碼,顯示這個問題可能是OK:Web客戶端也可以從磁盤,如果參照這樣引用本地文件。用你的一個,你最好展示適當的努力製作一個好的樣本 - 請查看http://sscce.org/來改進你的問題。 –

+0

錯誤信息對我來說似乎非常清晰簡潔;您不能將URI路徑與'File'類一起使用。你需要使用'WebClient'。 –

回答

-1

File.ReadAllLines不支持如錯誤消息中所述的直接URI路徑(雖然令人費解它如何在本地工作),只需將您的路徑分配給一個字符串,然後在請求中使用它。

string path = @"http://mywebsite.com/test/accounts.txt"; 
String[] saUsernames = File.ReadAllLines(path); 

編輯:由於沒有字符可以在字符串中轉義並只使用原始行,因此可以將@棄置。

+1

您的建議不起作用。 –

+1

是的,給出了與op相同的錯誤 – RichardB

0

File.ReadAllLines不支持http模式,如http。

嘗試,而不是:

string content; 
using (WebClient client = new WebClient()) 
{ 
    content = client.DownloadString("http://example.com/accounts.txt"); 
} 

'內容' 將包含文件的完整內容。使用string.Split()函數將內容拆分爲數組很簡單。

注:

@"file://c:\folder\account.txt"