Google api 如何在Google API中设置消息的日期
我有一个要求,比如在某些情况下更新gmail消息。因此,我试图通过删除现有消息并创建新消息来完成此任务。但我希望保留旧邮件的日期 假设7月1日发送了一条消息。我试图在7月3日更新消息内容。因此,在7月3日,我使用messageId删除了现有的消息,并创建了一条新消息。但是我需要创建一个日期为7月1日的消息 使用以下代码创建消息并发送Google api 如何在Google API中设置消息的日期,google-api,gmail-api,Google Api,Gmail Api,我有一个要求,比如在某些情况下更新gmail消息。因此,我试图通过删除现有消息并创建新消息来完成此任务。但我希望保留旧邮件的日期 假设7月1日发送了一条消息。我试图在7月3日更新消息内容。因此,在7月3日,我使用messageId删除了现有的消息,并创建了一条新消息。但是我需要创建一个日期为7月1日的消息 使用以下代码创建消息并发送 private static MimeMessage createEmail(Activity activity, String userId, String fr
private static MimeMessage createEmail(Activity activity, String userId, String fromAddress) throws MessagingException {
Properties props = new Properties();
Session session = Session.getInstance(props);
MimeMessage email = new MimeMessage(session);
InternetAddress tAddress = new InternetAddress(userId);
InternetAddress fAddress = new InternetAddress(fromAddress);
email.setFrom(fAddress);
email.addRecipient(RecipientType.TO, tAddress);
String subject = GoogleUtil.getFormattedEmailSubject(activity);
String text = GoogleUtil.getFormattedEmailText(activity);
email.setSubject(subject);
email.setText(text);
//TRYING TO SET THE DATE HERE IF AM RIGHT.
email.setSentDate(new Date(544543676346L));
return email;
}
private static Message createMessageWithEmail(MimeMessage email, List<String> labelIds) throws MessagingException, IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
email.writeTo(bytes);
String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());
Message message = new Message();
message.setLabelIds(labelIds);
message.setRaw(encodedEmail);
return message;
}
private static Message sendMessage(Gmail service, String userId, MimeMessage email, List<String> labelIds)
throws MessagingException, IOException {
Message message = createMessageWithEmail(email, labelIds);
message = service.users().messages().send(userId, message).execute();
return message;
}
private static MimeMessage createEmail(活动活动、字符串userId、字符串fromAddress)抛出消息异常{
Properties props=新属性();
Session=Session.getInstance(props);
MimeMessage email=新MimeMessage(会话);
InternetAddress tAddress=新的InternetAddress(用户ID);
InternetAddress fAddress=新的InternetAddress(fromAddress);
email.setFrom(fAddress);
email.addRecipient(RecipientType.TO,tAddress);
String subject=GoogleUtil.getFormattedEmailSubject(活动);
String text=GoogleUtil.getFormattedEmailText(活动);
email.setSubject(主题);
email.setText(文本);
//如果我是对的,试着在这里设定日期。
电子邮件。setSentDate(新日期(544543676346L));
回复邮件;
}
私有静态消息createMessageWithEmail(MimeMessage电子邮件,列表标签ID)引发MessagineException,IOException{
ByteArrayOutputStream字节=新建ByteArrayOutputStream();
email.writeTo(字节);
String encodedEmail=Base64.encodeBase64URLSafeString(bytes.toByteArray());
消息消息=新消息();
message.setLabelIds(labelIds);
message.setRaw(encodedmail);
返回消息;
}
私有静态消息sendMessage(Gmail服务、字符串用户ID、MIMessage电子邮件、列表标签ID)
抛出MessaginException、IOException{
Message Message=createMessageWithEmail(email,labelid);
message=service.users().messages().send(userId,message).execute();
返回消息;
}
您无法设置发送电子邮件时Gmail使用的电子邮件内部消息时间。但你可以在向收件箱发送电子邮件时做到这一点。只需设置为“dateHeader”
,就可以告诉Gmail,它应该根据电子邮件中的日期标题确定内部消息时间
publicstaticvoidinsertmessage(Gmail-Gmail,stringuserid,Message-Message)抛出IOException{
gmail.users().messages()
.insert(用户标识、消息)
.setInternalDateSource(“日期头”)//