2014-01-24 2 views
0

나는 안드로이드 초보자와 나는이 자습서를 SMTP link another SMTP tutorial안드로이드에서 SMTP를 사용하여 이메일을 보내지 못하셨습니까?

을 따랐다 그러나 불행하게도 내가 에뮬레이터/장치 S3, 나는 "CATCH"블록 메시지를 얻고하려고 할 때마다 이메일을 보내지 못했습니다. 이 활동에서 확장 클래스는

ImageView submitBtn = (ImageView)findViewById(R.id.askscreen_submit_btn); 
     submitBtn.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
      try { 
// CALL GetText method to make post method call 
       m = new Mail("[email protected]","password"); 
       sendEmail(v); 

      } catch (Exception ex) { 
        content.setText(" url exeption! "); 
       } 
      } 
     }); 
    } 
    public void sendEmail(View view){ 
     String[] toArr = {"[email protected]"}; // This is an array, you can add more emails, just separate them with a coma 
     m.setTo(toArr); // load array to setTo function 
     m.setFrom("[email protected]"); // who is sending the email 
     m.setSubject("subject"); 
     m.setBody("your message goes here"); 

     try { 
      //m.addAttachment("/sdcard/myPicture.jpg"); // path to file you want to attach 
      if(m.send()) { 
       // success 
       Toast.makeText(AskfatwaActivity.this, "Email was sent successfully.", Toast.LENGTH_LONG).show(); 
      } else { 
       // failure 
       Toast.makeText(AskfatwaActivity.this, "Email was not sent.", Toast.LENGTH_LONG).show(); 
      } 
     } catch(Exception e) { 
      // some other problem 
      Toast.makeText(AskfatwaActivity.this, "There was a problem sending the email.", Toast.LENGTH_LONG).show(); 
     } 

    } 

누군가가 이유가 무엇인지 좀 도와 주시겠습니까?

+0

전자 메일 api를 사용 하시겠습니까? –

+0

나는 또한이 튜토리얼을 따라 갔다. http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android – user3233280

+0

나는 위에서 언급 한 튜토리얼을 따라 몇 가지 중 하나는 나를 도울 수있다 – user3233280

답변

0

한번은이 코드를 구현했는데 꽤 낮은 수준이지만 솔직히 api를 사용하지 않으므로 업무를 수행했습니다 ... 실제로 제공 할 수있는 모든 도움, 또한 base64 코드에 유의하십시오. 사용자 이름과 비밀번호는 반드시 있어야합니다. base64로 인코딩되었으므로 일부 라이브러리를 원할 수도 있습니다.

import java.io.BufferedReader; 

import java.io.IOException; 
import java.io.InputStreamReader; 
import java.io.OutputStreamWriter; 
import java.io.PrintWriter; 

import java.net.Socket; 

import java.net.UnknownHostException; 

import javax.swing.JOptionPane; 

public class Email { 




     public static void main(String[] args) throws UnknownHostException, IOException { 


     Socket so = new Socket("smtp.mail.yahoo.com",25);  




BufferedReader inputStream = new BufferedReader(new InputStreamReader(so.getInputStream())); 
PrintWriter outputStream = new PrintWriter(new OutputStreamWriter(so.getOutputStream()),true); 


String enemail = JOptionPane.showInputDialog(null, "Enter your e-mail in BASEA64 code"); 
String password = JOptionPane.showInputDialog(null, "Enter your password in BASEA64 code"); 
String from  = JOptionPane.showInputDialog(null, "From"); 
String to  = JOptionPane.showInputDialog(null, "To"); 
String subject = JOptionPane.showInputDialog(null, "Subject"); 
String msg  = JOptionPane.showInputDialog(null, "Message"); 

outputStream.println("HELO ");  
System.out.println(inputStream.readLine()); 



outputStream.println("AUTH LOGIN");  
System.out.println(inputStream.readLine()); 




outputStream.println(enemail);  
System.out.println(inputStream.readLine()); 



outputStream.println(password);  
System.out.println(inputStream.readLine()); 


outputStream.println("VRFY");  
System.out.println(inputStream.readLine()); 

outputStream.println("MAIL FROM:<"+from+">");  
System.out.println(inputStream.readLine()); 


outputStream.println("RCPT TO:<"+to+">");  
System.out.println(inputStream.readLine()); 

outputStream.println("DATA");  
System.out.println(inputStream.readLine()); 


outputStream.println("Subject:"+subject); 
outputStream.println("FROM :<"+from+">"); 
outputStream.println("TO :<"+to+">"); 
outputStream.println(msg); 
outputStream.println("");  
outputStream.println(".");  
so.close(); 




     } 
     } 
+0

어떻게 일 했나요? 내가 base64를 사용하여 이메일과 pswd를 추가 할 수 있습니까? – user3233280

+0

저는 온라인 변환기를 사용하기 시작했다고 말하면 http://commons.apache.org/proper/commons-codec/download_codec.cgi –

+0

에서 라이브러리를 다운로드 할 수 있습니다. 위에서 언급 한 코드는 괜찮지 만 권장하지 않기 때문에 첨부 파일 코드를 사용해야합니다. 제발 내 코드를보고 그것에 몇 가지 변화를 주시길 바랍니다. – user3233280

관련 문제