ชี้แจงการกำหนดค่า Javamail

ผ่านแอปพลิเคชันของฉันโดยใช้ Javamail API หากฉันต้องการส่งอีเมลระหว่างที่อยู่อีเมลภายนอกสองรายการว่า gmail->yahoo หรือ yahoo->gmail หรือบัญชีอีเมลอื่นใดโดยไม่ต้องใช้การตรวจสอบสิทธิ์ กลไก ฉันจะกำหนดค่าคุณสมบัติ mail.smtp.host ได้อย่างไร

วิธีที่ถูกต้องในการกำหนดค่าคุณสมบัติ javamail สำหรับการส่งอีเมลระหว่างที่อยู่อีเมลภายนอกสองแห่งคืออะไร?

โค้ดตัวอย่างในการส่งเมลได้รับด้านล่าง:

Session session = Session.getDefaultInstance(new Properties(),null);
MimeMessage message = new MimeMessage(session);   
message.setFrom(new InternetAddress("[email protected]"));  
InternetAddress[] toAddress = {new InternetAddress("[email protected]")};  
message.setRecipients(Message.RecipientType.TO, toAddress);  
message.setSubject("test mail");  message.setText("test body");  
Transport.send(message);

person newcomer    schedule 03.12.2012    source แหล่งที่มา


คำตอบ (2)


เซิร์ฟเวอร์เมลสาธารณะส่วนใหญ่จำเป็นต้องมีการตรวจสอบสิทธิ์ หากคุณต้องการดำเนินการโดยไม่มีการตรวจสอบสิทธิ์ คุณจะต้องเรียกใช้เซิร์ฟเวอร์อีเมลของคุณเอง

person Bill Shannon    schedule 03.12.2012

นี่สำหรับ Gmail ลองดูสิ คุณต้องการ mail.jar

public static void main(String[] args) {
    final String username = "[email protected]";
    final String password = "your-pwd";

    Properties props = new Properties();
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.port", "587");

    Session session = Session.getInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("[email protected]"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("[email protected]"));
        message.setSubject("A Mail Subject");
        message.setText("Hey I'm sending mail using java api");

        Transport.send(message);

        System.out.println("Done");

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

แก้ไข :

ลิงก์สำหรับดาวน์โหลด Java mail Api พร้อมด้วย mail.jar

person vels4j    schedule 03.12.2012