我正在尝试通过我的Java Mail应用程序向我的朋友发送邮件.我能够成功完成,但邮箱中的接收者列显示完整的电子邮件地址,而不是发件人的姓名.我尝试更改各种参数,但邮箱仍会显示完整的电子邮件地址,而不是发件人的姓名.
使用此方法发送消息:
public void send(String key){
String to=key;
String from="mygmailid";
String subject="wassp";
String text="Hello";
Properties props=new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.user", "myname");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session mailSession=Session.getDefaultInstance(props);
Message simpleMessage=new MimeMessage(mailSession);
InternetAddress fromAddress=null;
InternetAddress toAddress=null;
try{
fromAddress=new InternetAddress(from);
toAddress=new InternetAddress(to);
}
catch(AddressException e){
e.printStackTrace();
}
try{
simpleMessage.setFrom(fromAddress);
simpleMessage.setRecipient(RecipientType.TO,toAddress);
simpleMessage.setSubject(subject);
simpleMessage.setText(text);
transport.connect("smtp.gmail.com",465, "myid@gmail.com", "mygmailpassword");
transport.sendMessage(simpleMessage, simpleMessage.getAllRecipients());
transport.close();
}
catch(MessagingException e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我将此方法称为:
public static void main(String[] args) {
MailSender mailer=new MailSender();
mailer.send("friendmail@gmail.com");
}
Run Code Online (Sandbox Code Playgroud) 是否可以向Java系统属性添加新值.如果有任何可以在Java系统属性中引入具有相应值的新密钥.
我试图在preparedStatement中使用to_date在oracle数据库中输入日期,但是我收到错误.
代码片段:
sql = "select Identifier from metadata where content_cdate >=to_date(?,'dd-mm-yyyy') and content_cdate < to_date(?,'dd-mm-yyyy') and status='published' and content_mdate is null";
ps.setString(1, commonUtil.dateToString(startTime));
Run Code Online (Sandbox Code Playgroud)
dateToString方法返回如下值:2012-01-01 12:00:00
错误:
[Oracle][ODBC][Ora]ORA-01861: literal does not match format string
Run Code Online (Sandbox Code Playgroud)
请指教.