0
我想送展望會議,但它不能正確 工作時,我跑我的代碼,它告訴我這個問題發送MS Outlook的會議請求
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. ay7sm2589668wib.9 - gsmtp
,這是我的發送級別的代碼
public class SendMailTest
{
public boolean send(String uniqueId, Date reviewDateStartTime,
String reviewLocation, int reviewDurationMnts, String from,
String to, String title, String reviewSubject,
String reviewDescription, String summary) throws Exception {
reviewDateStartTime = new Date();
String fromMail = from;
String toMail = to;
uniqueId = "123456";
reviewDescription = "testing only";
reviewSubject = "testing review subject";
title = "testing";
summary = "testing summary";
to="[email protected]";
reviewDurationMnts = 30;
reviewLocation="test location";
from=to;
String meetingStartTime = getReviewTime(reviewDateStartTime,
reviewDurationMnts, false);
String meetingEndTime = getReviewTime(reviewDateStartTime,
reviewDurationMnts, true);
Properties prop = new Properties();
StringBuffer sb = new StringBuffer();
StringBuffer buffer = null;
Session session = Session.getDefaultInstance(prop, null);
Message message = new MimeMessage(session);
try {
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put("mail.smtp.port", "25");
// Define message
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress
.parse(to, false));
message.setSubject(reviewSubject);
message.setHeader("X-Mailer", "test-Mailer");
// Create the message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
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:"
+ to + "\n" + "ORGANIZER:MAILTO:" + from + "\n"
+ "DTSTART:" + meetingStartTime + "\n" + "DTEND:"
+ meetingEndTime + "\n" + "LOCATION:"
+ reviewLocation + "\n" + "TRANSP:OPAQUE\n"
+ "SEQUENCE:0\n" + "UID:" + uniqueId
+ "@iquest.com\n" + "DTSTAMP:" + meetingEndTime
+ "\n" + "CATEGORIES:Meeting\n" + "DESCRIPTION:"
+ reviewDescription + ".\n\n" + "SUMMARY:"
+ summary + "\n" + "PRIORITY:1\n"
+ "CLASS:PUBLIC\n" + "BEGIN:VALARM\n"
+ "TRIGGER:PT1440M\n" + "ACTION:DISPLAY\n"
+ "DESCRIPTION:Reminder\n" + "END:VALARM\n"
+ "END:VEVENT\n" + "END:VCALENDAR");
messageBodyPart.setFileName("TestMeeting.ics");
messageBodyPart
.setDataHandler(new DataHandler(new ByteArrayDataSource(buffer.toString(), "text/iCalendar")));
messageBodyPart.setHeader("Content-Class",
"urn:content-classes:calendarmessage");
messageBodyPart.setHeader("Content-ID", "calendar_message");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);
}
catch (Exception me) {
me.printStackTrace();
}
return false;
}
public String getReviewTime(Date reviewDateTime, int rDuration, boolean flag) {
Calendar c = Calendar.getInstance();
SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");
c.setTime(reviewDateTime);
if (flag == true) {
c.add(Calendar.MINUTE, rDuration);
}
String hour = c.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
+ c.get(Calendar.HOUR_OF_DAY) : ""
+ c.get(Calendar.HOUR_OF_DAY);
String min = c.get(Calendar.MINUTE) < 10 ? "0" + c.get(Calendar.MINUTE)
: "" + c.get(Calendar.MINUTE);
String sec = c.get(Calendar.SECOND) < 10 ? "0" + c.get(Calendar.SECOND)
: "" + c.get(Calendar.SECOND);
String date = s.format(new Date(c.getTimeInMillis()));
String dateTime = date + "T" + hour + min + sec;
return dateTime;
}
private class ByteArrayDataSource implements DataSource {
private byte[] data; // data for mail message
private String type; // content type/mime type
ByteArrayDataSource(String data, String type) {
try {
// Assumption that the string contains only ascii
// characters ! Else just pass in a charset into this
// constructor and use it in getBytes()
this.data = data.getBytes("iso-8859-1");
} catch (Exception e) {
e.printStackTrace();
}
this.type = type;
}
// DataSource interface methods
public InputStream getInputStream() throws IOException {
if (data == null)
throw new IOException(
"no data exception in ByteArrayDataSource");
return new ByteArrayInputStream(data);
}
public OutputStream getOutputStream() throws IOException {
throw new IOException("illegal operation in ByteArrayDataSource");
}
public String getContentType() {
return type;
}
public String getName() {
return "dummy";
}
}
public static void main(String args[]) throws Exception
{
SendMailTest s=new SendMailTest();
s.send("01",new Date(), "sale1", 2, "[email protected]", "someone", "test", "test", "test", "test");
}
}
任何一個可以幫助我,給我一個解決方案或什麼是錯的,並感謝
當我收到的電子郵件(在我的Gmail帳戶),它不能被顯示在前景 有你這個 – Amin
任何信息我想發送會議到Outlook,所以我加我gmail帳戶並將會議發送到此電子郵件,但它在gmail帳戶上收到但未在Outlook中顯示 – Amin
聽起來像您在將Outlook與Gmail同步時遇到問題。這是一個與當前問題不同的問題,很可能是配置問題。 – Deadron