0
我不是一个非常有经验的编码器,但我一直在学习。现在我正在编写测试电子邮件机器人程序,以发送电子邮件。当我尝试创建它时,遇到了一个问题,因此您可以在JOptionPane对话框中输入邮件的消息和主题。Java发送电子邮件bot与JOptionPane的自定义消息
下面是代码,看看顶部的字符串和messageobjs底部..
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;
import javax.swing.JOptionPane;
public class Ebot2
{
public static void main(String[] args)
{
String Dest;
Dest = JOptionPane.showInputDialog("Who would you like to message?");
String Subject;
Subject = JOptionPane.showInputDialog("What is the message subject?");
String Message;
Message = JOptionPane.showInputDialog("What is the message?");
String sendrmailid = "[email protected]";
final String uname = "email";
final String pwd = "pass";
Properties propvls = new Properties();
propvls.put("mail.smtp.auth", "true");
propvls.put("mail.smtp.starttls.enable", "true");
propvls.put("mail.smtp.host", "smtp.gmail.com");
propvls.put("mail.smpt.port", "25");
Session sessionobj = Session.getInstance(propvls,
new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(uname, pwd);
}
});
try
{
Message messageobj = new MimeMessage(sessionobj);
messageobj.setFrom(new InternetAddress(sendrmailid));
messageobj.setRecipients(Message.RecipientType.TO,InternetAddress.parse(Dest));
messageobj.setSubject(Subject);
messageobj.setText(Message);
Transport.send(messageobj);
System.out.println("Your email sent successfully....");
}
catch (MessagingException exp)
{
throw new RuntimeException(exp);
}
}
}
遗憾的狗屎格式,代码块事情是困难的。无论如何,错误林开始,我改变了setSubject和setText到通过JOptionPane输入的字符串。错误是...
Ebot2.java:53: error: cannot find symbol
messageobj.setRecipients(Message.RecipientType.TO,InternetAddress.parse(Dest));
^
symbol: variable RecipientType
location: variable Message of type String
1 error
感谢任何人的答案,我真的需要帮助!
检查您的进口?消息缺失 – Saravana
添加'import javax.mail.Message.RecipientType;' – PeterMmm
我添加了java邮件消息recipienttype导入,但它并没有影响任何东西。我仍然得到相同的错误。请记住,在添加消息和主题区域的所有JOptionPane内容之前,代码工作得非常好。我应该只是拿出消息和主题的JOptionPane的东西? – Dillon