【问题标题】:How to attach an invite to mail?如何在邮件中附加邀请?
【发布时间】:2019-07-24 13:23:40
【问题描述】:

我已经在 Microsoft 授权服务器上注册了我的应用程序并完成了该过程,直到我获得了文档中给出的访问令牌。 我真正期待的只是创建事件并将其发送到用户邮件的步骤。

我有我的应用程序的访问令牌。 我知道的步骤,但不知道它们是否正确: 创建日历 创建活动 将事件插入日历 并将该日历添加到邮件中。

在获取访问令牌之前,代码与文档中给出的相同。

我希望收到邀请,以便用户可以对其执行操作。

我需要在 java(Spring boot) 中使用邀请发送邮件。

  public class Graph 
{
     private static IGraphServiceClient graphClient = null;
        private static SimpleAuthProvoider authProvider = null;

        private static void ensureGraphClient(String accessToken) {
            if (graphClient == null) {
                // Create the auth provider
                authProvider = new SimpleAuthProvoider(accessToken);

                // Create default logger to only log errors
                DefaultLogger logger = new DefaultLogger();
                logger.setLoggingLevel(LoggerLevel.ERROR);

                // Build a Graph client
                graphClient = GraphServiceClient.builder()
                    .authenticationProvider(authProvider)
                    .logger(logger)
                    .buildClient();
            }
        }
       // @GetMapping(value="/getUserDetails")
        public static String getUser(String accessToken) {
            ensureGraphClient(accessToken);

            // GET /me to get authenticated user
            User me = graphClient
                .me()
                .buildRequest()
                .get();
            System.out.println("This is an user "+me.userPrincipalName);
            return "here we are getting user information";
        }
}

以同样的方式,我也可以获取用户的日历并创建一个事件,但我想通过邮件发送带有该事件的日历,以便用户可以添加自己。

【问题讨论】:

  • 您的问题似乎没有得到任何答案,因为您的问题不是很清楚。你的代码是什么?
  • @4castle 我已经用代码更新了问题,基本上它是代码,直到我获得授权码、ide 令牌和访问令牌,现在我想创建一个事件并将其发送到一些邮件和然后用户可以将其添加到日历中?我没有得到的是我们创建事件并将其添加到日历和发送邮件的部分?
  • @4castle 而不是这样做,现在我只是创建一个 ics 文件并通过邮件发送它:)

标签: spring spring-boot microsoft-graph-api office365api outlook-restapi


【解决方案1】:

还查看了iCalendar specification. 以了解各种属性。

public static String getCalendarInvite(MailDTO mailDTO) {
    // DTSTART,DTEND field needs a format yyyyMMddT000000 for a full day event,
    // where 000000 defines full day event

    //here DateFormatter of JodaTime Lib is used for date formatting.
    String DTSTART = DateUtils.formatDatesForICSCalendar(mailDTO.getEventStartDate());
    String DTEND = DateUtils.formatDatesForICSCalendar(mailDTO.getEventEndDate());

    // generating random number,so that UID of calendar object will always be
    // different.
    UUID uuid = UUID.randomUUID();
    String randomUUIDString = uuid.toString();

    StringBuffer sb = new StringBuffer();
    StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n"
            + "PRODID:-//Microsoft Corporation//Outlook 15.0 MIMEDIR//EN\\n" + "VERSION:2.0\n" + "METHOD:REQUEST\n"
            + "BEGIN:VEVENT\n" + "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:"
            + mailDTO.getAttendeeMail() + "\n" + "ORGANIZER:MAILTO:" + mail.getOrganizerMail()
            + "\n" + "DTSTART;TZID=Asia/Calcutta:" + DTSTART + "\n" + "DTEND;TZID=Asia/Calcutta:" + DTEND + "\n"
            + "LOCATION:" + mairDTO.getLocation() + "\n" + "TRANSP:OPAQUE\n" + "SEQUENCE:0\n" + "UID:"
            + randomUUIDString + "\n" + "DTSTAMP:20180922T120102Z\n" + "CATEGORIES:Interview\n" + "DESCRIPTION:"
            + mailDTO.getDescription() + "\n\n" + "SUMMARY:" + mailDTO.getSummary() + "\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");

    String calendarInvite = buffer.toString();
    return calendarInvite;
}

【讨论】:

    猜你喜欢
    • 2014-11-28
    • 1970-01-01
    • 2016-06-23
    • 2020-11-18
    • 2015-01-04
    • 2011-02-18
    • 2021-11-15
    • 1970-01-01
    • 2011-12-15
    相关资源
    最近更新 更多