2015-09-26 59 views
0

我無法通過的JavaMail API 該按鈕,發送郵件是代碼:客戶端主機 - JavaMail的

package my.eliank.lgg.robots; 

import java.time.LocalDateTime; 
import java.util.Properties; 

import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 

import my.eliank.lgg.MainFrame; 

    public class MailBot { 

     private String sender; 
     private String host; 
     private Properties properties; 
     private Session session; 

     public MailBot() { 
      sender = "[email protected]"; 
      host = "mx1.freehostingnoads.net"; 
      properties = System.getProperties(); 
      properties.setProperty("mail.smtp.host", host); 
      properties.setProperty("mail.smtp.port", "2525"); 
      properties.setProperty("mail.smtp.user", "user"); 
      properties.setProperty("mail.smtp.password", "password"); 
      session = Session.getDefaultInstance(properties); 
     } 

     public void sendMail(String recipient) { 
      try { 
       MimeMessage message = new MimeMessage(session); 
       message.setFrom(new InternetAddress(sender)); 
       message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); 
       message.setSubject("Lotto numbers generation @" + LocalDateTime.now().toString().substring(0, 10)); 
       message.setText(MainFrame.textAreaOutput.getText()); 

       Transport.send(message); 
       System.out.println("Message was successfully sent"); 
      } catch (MessagingException e) { 
       e.printStackTrace(); 
      } 
     } 

    } 

的問題是,每當我試圖通過主機發送一個郵件 我得到這個例外:

javax.mail.SendFailedException: Invalid Addresses; 
    nested exception is: 
    com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 Service unavailable; Client host [79.177.150.73] blocked using zen.spamhaus.org; http://www.spamhaus.org/query/bl?ip=79.177.150.73 

    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1873) 
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1120) 
    at javax.mail.Transport.send0(Transport.java:195) 
    at javax.mail.Transport.send(Transport.java:124) 
    at my.eliank.lgg.robots.MailBot.sendMail(MailBot.java:41) 
    at my.eliank.lgg.MainFrame$2.actionPerformed(MainFrame.java:108) 
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
    at java.awt.Component.processMouseEvent(Unknown Source) 
    at javax.swing.JComponent.processMouseEvent(Unknown Source) 
    at java.awt.Component.processEvent(Unknown Source) 
    at java.awt.Container.processEvent(Unknown Source) 
    at java.awt.Component.dispatchEventImpl(Unknown Source) 
    at java.awt.Container.dispatchEventImpl(Unknown Source) 
    at java.awt.Component.dispatchEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
    at java.awt.Container.dispatchEventImpl(Unknown Source) 
    at java.awt.Window.dispatchEventImpl(Unknown Source) 
    at java.awt.Component.dispatchEvent(Unknown Source) 
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
    at java.awt.EventQueue.access$500(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.awt.EventQueue$3.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.awt.EventQueue$4.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
    at java.awt.EventQueue.dispatchEvent(Unknown Source) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
    at java.awt.EventDispatchThread.run(Unknown Source) 

這垃圾郵件IP塊是什麼意思,我該如何刪除它?我正試圖通過我的主人發送一封郵件,號碼爲http://www.freewebhostingnoads.net,爲什麼我一直被阻止?

+0

我投票結束這個問題作爲題外話,因爲它是關於電子郵件的產能,而不是編程。 – tripleee

+0

我一開始以爲我的代碼存在問題,看起來原因是不同的,它的目的是成爲一個編程問題。我同意,它成爲脫離主題,應該被關閉。 (但爲什麼要低調呢?這是一個合法的問題) –

+0

如果你同意這是題外話,你怎麼還說它是合法的?儘管此類問題不屬於主題,但這種類型的問題在這裏大量複製,因此downvoting有助於保持網站清潔(帶有否定投票的封閉問題可以刪除)。如果您想進一步討論,請邀請您在https://meta.stackoverflow.com/上單獨打開一個問題。 – tripleee

回答

2

有人使用您的IP地址,也許該網站託管服務上該IP地址的以前用戶,被認爲是發送垃圾郵件。按照錯誤消息中的鏈接,它會告訴你該怎麼做。如果您使用動態IP地址,則可能需要切換到靜態IP地址。

+0

我沒有看到它爲什麼會這樣做的原因,當我通過Gmail的SMTP發送郵件時,它工作得很好,但我無法通過主機發送郵件,除此之外,鏈接還導致我擁有阻止所有動態IP地址的spamhaus在PBL列表下,所以我不明白它爲什麼可以與GMail一起工作,並且不適用於我使用的主機。 –

+0

不同的服務器使用不同的規則來決定阻止什麼。 –

+0

然後我假設我嘗試連接的服務器阻止我的託管網站的服務器作爲反垃圾郵件測量,如果情況不是這樣,我可以做的事情可能不多,也許切換到更可信的託管站點,不會受到大型免費郵件提供商的阻止,或者啓動我自己的服務器以使其工作,同時我會使用Gmail的SMTP服務,感謝您的幫助。 –

相關問題