先谢谢您的帮助和支持。
使用下面的代码,我能够打开我的outlook,并指定TO,CC主题和邮件正文,但我无法自动发送邮件,请大家帮忙。
package com.emailtrigger;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class sendMail
{
public static void main(String[] args) throws URISyntaxException
{
String subject="Email Testing through Code";
String body="This is testing purpose";
String cc="[email protected]";
try {
Desktop.getDesktop().mail( new URI( "mailto:[email protected]?subject="+subject+"&cc="+cc+"&body="+body) );
}
catch ( IOException ex )
{
}
}
}
如果你会打印错误,那么它是: Illegal character in opaque part
.
你不应该在数值之间提供空格。参考资料
所有值都应该是URL编码的 (e.g. space becomes %20)
如何对URL进行编码
你的代码在上面的情况下-
public static void main(String[] args) throws URISyntaxException {
String subject="Email%20Testing%20through%20Code";
String body="This%20is%20testing%20purpose";
String cc="[email protected]";
try {
Desktop.getDesktop().mail( new URI( "mailto:[email protected]?subject="+subject+"&cc="+cc+"&body="+body) );
}
catch ( IOException ex ) {
ex.printStackTrace();
}
}