这是我的密码:
prop.load(new FileInputStream("config.properties"));
String emailTo = prop.getProperty("To");
String emailCC = prop.getProperty("CC");
String emailBCC = prop.getProperty("BCC")
String[] to = emailTo.trim().split(",");
String[] cc = emailCC.trim().split(",");
String[] bcc = emailBCC.trim().split(",");
--- Note: Value of CC and BCC is blank in properties fileconfig.properties
To = tarique.khan@test.com
CC =
BCC =--我试过了,我认为这是因为CC和BCC的零值,但是如何解决它。我没有头绪。
异常发生:
DEBUG: setDebug: JavaMail version 1.3.1
javax.mail.internet.AddressException: Illegal address in string ``''
at javax.mail.internet.InternetAddress.<init>(InternetAddress.java:68)
at com.neosoft.reporting.SendEmail.sendMail(SendEmail.java:165)
at com.neosoft.reporting.SendEmail.execute(SendEmail.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)传递参数的sendMail()声明:
如果属性文件中CC和BCC的值为空,那么应该传递什么方法。
SendEmail.sendMail("testrobot.personiphi@gmail.com", "xxxx", "smtp.gmail.com",
"465", "true", "true", true,
javax.net.ssl.SSLSocketFactory.class.getCanonicalName(),
"false", to, cc, bcc, "Automation Test Report",
"Hi \n Here is your test report of current run that was initiated.",
path, reportFileName);
}
public static boolean sendMail(String userName, String passWord, String host, String port,
String starttls, String auth, boolean debug, String socketFactoryClass,
String fallback, String[] to, String[] cc, String[] bcc,
String subject, String text, String attachmentPath, String attachmentName)发布于 2014-10-20 09:21:32
首先,像您所做的那样从CC文件中获取config.properties & BCC
String emailTo = prop.getProperty("To");
String emailCC = prop.getProperty("CC");
String emailBCC = prop.getProperty("BCC")然后检查它们是否像NULL一样
String[] cc;
String[] bcc;
if(emailCC.length() != 0){
cc = emailCC.trim().split(",");
}else if(emailBCC.length() != 0){
bcc = emailBCC.trim().split(",");
}当cc & bcc是null时,然后在sendMail()中添加以下条件:
for(int i = 0; i < cc.length; i++) {
if(!cc[i].isEmpty())
message.addRecipient(Message.RecipientType.CC, new InternetAddress(cc[i]));
}
for(int i = 0; i < bcc.length; i++) {
if(!bcc[i].isEmpty())
msg.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc[i]));
}我希望这能解决你的问题。
https://stackoverflow.com/questions/26461344
复制相似问题