我正在尝试使用Java Mail
Library将iCal发送到Outlook,我已经阅读了[Question](http://codingdict.com/questions/122902,并且已经有一些示例代码
public class SendMeetingRequest {
String host = "" ;
String port = "" ;
String sender = "" ;
public static SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyyMMdd'T'HHmm'00'" ) ;
public static SimpleDateFormat dateParser = new SimpleDateFormat( "dd-MM-yyyy HH:mm" ) ;
public static void main(String[] args) throws Exception {
SendMeetingRequest sender = new SendMeetingRequest() ;
sender.sendInvitation( “LogicaCMG Inschrijf Site”
, new String[] { “robert<dot>willems<dot>of<dot>brilman<at>logicacmg<dot>com”
}
, “Outlook Meeting Request Using JavaMail”
, dateParser.parse( “28-08-2006 18:00″ )
, dateParser.parse( “28-08-2006 21:00″ )
, “LIS-42″
, “Bar op scheveningen”
, “<font color=\”Red\”>Aanwezigheid verplicht!</font><br>We gaan lekker een biertje drinken met z’n allen.”
) ;
}
void sendInvitation( String organizer
, String[] to
, String subject
, Date start
, Date end
, String invitationId
, String location
, String description
) throws Exception {
try {
Properties prop = new Properties();
prop.put(”mail.smtp.port”, port );
prop.put(”mail.smtp.host”, host );
Session session = Session.getDefaultInstance(prop);
session.setDebug(true);
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
// Set TO
if( to != null && ( to.length > 0 ) ) {
InternetAddress[] address = new InternetAddress[ to.length ] ;
for( int i = 0; i < to.length; i++ ) {
address[ i ] = new InternetAddress( to[ i ] ) ;
}
message.setRecipients( Message.RecipientType.TO, address ) ;
}
// Set subject
message.setSubject(subject);
// Create iCalendar message
StringBuffer messageText = new StringBuffer();
messageText.append("BEGIN:VCALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"ORGANIZER:MAILTO:" ) ;
messageText.append( organizer ) ;
messageText.append( "\n" +
"DTSTART:");
messageText.append( dateFormat.format( start ) ) ;
messageText.append( "\n" +
"DTEND:" ) ;
messageText.append( dateFormat.format( end ) ) ;
messageText.append( "\n" +
"LOCATION:" ) ;
messageText.append( location ) ;
messageText.append( "\n" +
"UID:" ) ;
messageText.append( invitationId ) ;
messageText.append( "\n" +
"DTSTAMP:" ) ;
messageText.append( dateFormat.format( new java.util.Date() ) ) ;
messageText.append( "\n" +
"DESCRIPTION;ALTREP=\"CID:<eventDescriptionHTML>\”" ) ;
messageText.append( “\n” +
”BEGIN:VALARM\n” +
”TRIGGER:-PT15M\n” +
”ACTION:DISPLAY\n” +
”DESCRIPTION:Reminder\n” +
”END:VALARM\n” +
”END:VEVENT\n” +
”END:VCALENDAR”
) ;
Multipart mp = new MimeMultipart();
MimeBodyPart meetingPart = new MimeBodyPart() ;
meetingPart.setDataHandler( new DataHandler( new StringDataSource( messageText.toString(), “text/calendar”, “meetingRequest” ) ) ) ;
mp.addBodyPart( meetingPart ) ;
MimeBodyPart descriptionPart = new MimeBodyPart() ;
descriptionPart.setDataHandler( new DataHandler( new StringDataSource( description, “text/html”, “eventDescription” ) ) ) ;
descriptionPart.setContentID( “<eventDescriptionHTML>” ) ;
mp.addBodyPart( descriptionPart ) ;
message.setContent( mp ) ;
// send message
Transport.send(message);
} catch (MessagingException me) {
me.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static class StringDataSource implements DataSource {
private String contents ;
private String mimetype ;
private String name ;
public StringDataSource( String contents
, String mimetype
, String name
) {
this.contents = contents ;
this.mimetype = mimetype ;
this.name = name ;
}
public String getContentType() {
return( mimetype ) ;
}
public String getName() {
return( name ) ;
}
public InputStream getInputStream() {
return( new StringBufferInputStream( contents ) ) ;
}
public OutputStream getOutputStream() {
throw new IllegalAccessError( “This datasource cannot be written to” ) ;
}
} }
但是它是作为Outlook 2007和Outlook
2003的附件发送的,即使单击附件进行查看和接受,也不会收到“答案”,这是应用程序具有类似Outlook的功能的目的。
有什么我需要知道的过程吗?还是邀请ID会使事情变得更糟?
所以我解决了这个问题,这是我发现的:
1-您必须更新到Java Mail API 1.4.2,才能使一切正常运行
2-编写消息的文本/日历部分,如下所示:
package com.xx.xx;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
public class Email {
public Email() {
}
/*
* @param args
*/
public static void main(String[] args) {
try {
Email email = new Email();
email.send();
} catch (Exception e) {
e.printStackTrace();
}
}
public void send() throws Exception {
try {
String from = "xx@xx.com";
String to = "xx@xx.com";
Properties prop = new Properties();
prop.put("mail.smtp.host", "mailhost");
Session session = Session.getDefaultInstance(prop, null);
// Define message
MimeMessage message = new MimeMessage(session);
message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=VEVENT");
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Outlook Meeting Request Using JavaMail");
StringBuffer sb = new StringBuffer();
StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:xx@xx.com\n" +
"ORGANIZER:MAILTO:xx@xx.com\n" +
"DTSTART:20051208T053000Z\n" +
"DTEND:20051208T060000Z\n" +
"LOCATION:Conference room\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:0\n" +
"UID:040000008200E00074C5B7101A82E00800000000002FF466CE3AC5010000000000000000100\n" +
" 000004377FE5C37984842BF9440448399EB02\n" +
"DTSTAMP:20051206T120102Z\n" +
"CATEGORIES:Meeting\n" +
"DESCRIPTION:This the description of the meeting.\n\n" +
"SUMMARY:Test meeting request\n" +
"PRIORITY:5\n" +
"CLASS:PUBLIC\n" +
"BEGIN:VALARM\n" +
"TRIGGER:PT1440M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
messageBodyPart.setHeader("Content-Class", "urn:content- classes:calendarmessage");
messageBodyPart.setHeader("Content-ID", "calendar_message");
messageBodyPart.setDataHandler(new DataHandler(
new ByteArrayDataSource(buffer.toString(), "text/calendar")));// very important
// Create a Multipart
Multipart multipart = new MimeMultipart();
// Add part one
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// send message
Transport.send(message);
} catch (MessagingException me) {
me.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
3-替换变量,一切顺利!
我有一个本地服务器在我的计算机上运行,它有一个内置的REST API。api的基本url为:http://127.0.0.1:8090/ehr/api/v1.现在我想用这个api为这个服务器创建一个客户端应用程序。要登录此服务器,api url为baseurl/login with POST method。它将用户名、密码和组织作为参数,如果登录成功,则返回json格式的身份验证令牌。现在我想用h
问题内容: 我正在尝试在我的项目中使用volley来处理我的所有HTTP请求,因为据我所知,这是最高效的请求。因此,我通过遵循此AndroidHive教程开始学习排球。 我的第一个GET请求成功。然后我转到POST请求,但失败了。我在Stack Overflow上看到很多人在将volley的后期请求与PHP结合在一起时遇到问题。我相信我们无法使用常规方法来访问它,因为凌空将JSON对象发送到我们指
客户端通过HTTP请求(通过浏览器post)调用Servlet,然后Servlet应向外部网站发送请求(get),并从网站接收响应(post)。servlet继续响应并向客户端发送响应(post)。 我的问题是如何在Servlet中发送和接收请求/响应并将某些内容发送回客户端?
我必须创建一个tcp客户端 1) -将向服务器发送请求消息并接收响应 2)-有时服务器将msg推送到客户端,而没有来自客户端的任何请求,因此客户端应该接受并阅读它。 因此,我已经就其中的第1部分提出了问题,我的tcp客户端使用spring集成无法得到响应,并试图找到一些解决方案。但对于第二部分,我不知道如何使用tcpoutboundgateway或带有客户机标志enable的inboundgate
这是我第一次尝试进行基本身份验证,但似乎没有任何效果。Axios post未发送数据/控制器未返回响应。我找不到我到底哪里出错了,但我想知道我的http post请求的主体是否必须与requestbody匹配,或者我需要做什么更改才能让UserRepository将表单dat保存在数据库中? }
我在spring mvc 3.2.2中使用apache http客户端同步发送5个get请求,如图所示。 如何异步(并行)发送所有这些内容并等待请求返回,以便从所有 GET 请求返回已解析的有效负载字符串?