简体   繁体   English

发送MS Outlook会议请求

[英]Sending MS Outlook Meeting Request

i want to send outlook meeting but it does not work correctly when i run my code it show me this problem 我想发送Outlook会议,但是当我运行代码时它无法正常工作,它向我显示此问题

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. ay7sm2589668wib.9 - gsmtp

and this is my code of the sending class 这是我的发送类代码

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="amine.minyawi@gmail.com";
        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, "aminee1988@hotmail.com", "someone", "test", "test", "test", "test");

}
}

any one help me and give me a solution or what is wrong and thanks 任何人都可以帮助我,并给我解决方案,或者出了什么问题,谢谢

It appears that google uses secure smtp over TLS(Transport Level Security). 看来Google在TLS(传输级安全性)上使用了安全的smtp。 The following RFC describes the process and may help here http://tools.ietf.org/html/rfc3207 以下RFC说明了该过程,并可能在此处提供帮助: http://tools.ietf.org/html/rfc3207

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM