私はJavaからメールを送信するためのスタンドアロンコードを書いています。このプログラムでは、私はコンソール上のすべての情報をユーザーがとっています。しかしここでの問題は認証部分にあります。 私は実際にメールIDと送信者のpasswrdであるユーザー名とパスワードを渡しています。しかし、最終的な変数でないパスワードを参照することはできません。は最終的な変数でないパスワードを参照することはできません
もし私がそれを最後にしたら、私はそれをユーザーから受け取ることができません。私は何をすべきですか?
package mypackage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMailSSL {
public static void main(String[] args) throws IOException {
Properties props = new Properties();
String host="";
String port="";
String s_port="";
String to ="";
final String from="";
final String password="";
String subject="";
String context="";
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("CONFIGURATION.... ");
System.out.println("mail.smtp.host=");
host = in.readLine();
System.out.println("mail.smtp.socketfactoryport=");
s_port=in.readLine();
props.put("mail.smtp.host", host);
props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.port", s_port);
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
System.out.println("mail.smtp.port=");
port=in.readLine();
props.put("mail.smtp.port", port);
System.out.println("AUTHENTICATION....");
System.out.println("Username=");
from=in.readLine();
System.out.println("Password=");
password = in.readLine();
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator()
{
String from = "";
String password="";
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(from,password);
}
});
try {
System.out.println("Mail Sending Process..");
System.out.println("To=");
to=in.readLine();
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
System.out.println("Subject=");
subject=in.readLine();
message.setSubject(subject);
System.out.println("Context=");
context = in.readLine();
message.setText(context);
Transport.send(message);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
System.out.println("in catch blk");
throw new RuntimeException(e);
}
}
}
あなたの助けは私の貴重なものです。 ありがとうございます。
大変感謝しています。:) – Atul
はい私は書いています。私はC言語のプログラミングとJavaの新しいプログラミングにもっと慣れています – Atul
それを聞いてうれしい!回答が助けられた場合は、アップ投票をしたり、答えを受け入れることを検討してください。それは質問に答えてくれる私たちを幸せに保ちます。 ;) – stevevls