新サーバーへ、CentOS release 6.7 (Final)をインストールし(apatch、tomcat、MySQL、JAVAなど、その他)、
localhostを使って、メールを送信しようとしたところ、
下記のエラーがでます。
JAVAから送信しようとすると、エラーになり、送信できません。
1.原因は、何でしょうか?
2.また、下記サンプルコードをどのようにかえればよいでしょうか?
3.サーバーの設定ファイルを変える部分があれば、教えてください。
■# echo miodesu | mail mio@softwere.jp は、送信でき、メールソフトで受信できた。
■/var/log/maillog には、ログが出力されていない。
■catalina.outのログ
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 560 4.3.1
mio@softwere.jp... Relaying denied. Proper authentication required.
■ネットから拾ってきたソースの下記でやっても同じエラーがでます。(JAVAのソースをJSPへ変えた)
====================================
<%@ page language='java' contentType="application/json;" session="true" pageEncoding="UTF-8"%>
<%@ page import="java.util.Properties"%>
<%@ page import="java.util.Date"%>
<%@ page import="javax.mail.Session"%>
<%@ page import="javax.mail.Transport"%>
<%@ page import="javax.mail.MessagingException"%>
<%@ page import="javax.mail.internet.InternetAddress"%>
<%@ page import="javax.mail.internet.MimeMessage"%>
<%@ page import="javax.mail.internet.AddressException"%>
<%
Properties properties=new Properties();
properties.setProperty("mail.smtp.host", "localhost");
Session session2=Session.getDefaultInstance(properties);
String[] args = {"mio@softwere.jp"};
MimeMessage mimeMessage=new MimeMessage(session2);
// InternetAddressの作成
InternetAddress[] toAddress=new InternetAddress[args.length];
try{
for(int i=0; i<args.length; i++){
toAddress[i]=new InternetAddress(args[i]);
}
}catch(AddressException e){
e.printStackTrace();
// return;
}
try{ // 宛先の設定 mimeMessage.setRecipients(MimeMessage.RecipientType.TO, "mio@softwere.jp"); // 送信元の設定 mimeMessage.setFrom(new InternetAddress("from@test.com")); // サブジェクトの設定 mimeMessage.setSubject("The time is ..."); // 本文の設定 mimeMessage.setText(new Date().toString()); // 設定の保存 mimeMessage.saveChanges(); // メールの送信 Transport.send(mimeMessage); }catch(MessagingException e){ e.printStackTrace();
// return;
}
%>
====================================
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。