2013-10-12 26 views
1

我使用JavaMail API和我能夠從[email protected]發送郵件至​​。我們可以通過JavaMail API發送郵件([email protected]到另一個郵件地址)嗎?

現在,我想:

我想從發送電子郵件[email protected][email protected]等/等

發送郵件服務器:smtp.rediffmail.com

端口號:25

O/p:javax.mail.AuthenticationExcepetion,

什麼變化nece這是可能的還是不可能。

+0

希望你能從這裏得到你的答案:http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in- a –

+0

我這樣做了,但我想發送郵件到其他域,如我在上面的查詢中提到@ shree202 –

+0

我不明白。您只需更改「至」電子郵件地址。什麼是真正的問題? – Simon

回答

0

試試這個片段改變你的SMTP服務器。 雅虎: 發送郵件服務器(SMTP):plus.smtp.mail.yahoo.com 使用SSL,端口:465,使用身份驗證。

段:

Properties props = new Properties(); 
    props.put("mail.smtp.user", myEmail); 
    props.put("mail.smtp.host", smptServer); 
    props.put("mail.smtp.port", port); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.socketFactory.port", port); 
    props.put("mail.smtp.socketFactory.class", 
      "javax.net.ssl.SSLSocketFactory"); 
    props.put("mail.smtp.socketFactory.fallback", "false"); 

    SecurityManager security = System.getSecurityManager(); 

    try { 
     Authenticator auth = new autentificadorSMTP(); 
     Session session = Session.getInstance(props, auth); 
     // session.setDebug(true); 

     MimeMessage msg = new MimeMessage(session); 
     msg.setText(body); 
     msg.setSubject(subject); 
     msg.setFrom(new InternetAddress(myEmail)); 
     msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
       toEmail)); 
     Transport.send(msg); 
    } catch (Exception mex) { 
     mex.printStackTrace(); 
    } 

的Util:

private class authSMTP extends javax.mail.Authenticator { 
    public PasswordAuthentication getPasswordAuthentication() { 
     return new PasswordAuthentication(myEmail, myPass); 
    } 
} 

希望它能幫助!

+0

我試過這個,但得到錯誤。 –

+0

什麼錯誤?這裏發佈:) – jsanchez

+0

等待............. –

相關問題