2
모든 유형의 호스트와 함께 보내야하는 메일 프로그램이 필요합니다. smtp를 사용했지만 gmail 만 지원합니다. 프로젝트에서 메일은 회사 login.There에서 보내야합니다. 회사 로그인의 그들은 서로 다른 유형의 메일 계정을 가질 수 있습니다 ... 나는 모든 유형의 메일 계정을 지원하는 단일 프로그램을 작성해야합니다.서블릿을 사용하여 JSP로 메일을 보내려면
package com.admin;
/**
*
* @author asp.net
*/
import java.util.Date;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
* A utility class for sending e-mail messages
* @author www.codejava.net
*
*/
public class EmailUtility {
public static void sendEmail(String host, String port,
final String userName, final String password, String toAddress,
String subject, String message) throws AddressException,
MessagingException {
// sets SMTP server properties
Properties properties = new Properties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", port);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.transport.protocol", "smtp") ;
// creates a new session with an authenticator
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
};
Session session = Session.getInstance(properties, auth);
// creates a new e-mail message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(userName));
InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
// sends the e-mail
Transport.send(msg);
}
}
고용주가 여러분에게 제공 한 도전적이고 독특한 기회가 무엇인지, 저는 여러분에게 행운이 있기를 바란다 고 생각합니다. –
여러 가지 유형의 메일 계정에 대해 SMTP를 사용하려고하면 어떤 오류가 발생 했습니까? 코드 공유 –
감사합니다 - Elliott Frisch – Priya