第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 Java 中的 Gmail API 創(chuàng)建帶有 PDF 文件作為附件的草稿

使用 Java 中的 Gmail API 創(chuàng)建帶有 PDF 文件作為附件的草稿

烙印99 2023-04-26 13:51:09
我正在嘗試使用 Gmail API 在 Java 中創(chuàng)建帶有附件的草稿。創(chuàng)建一個(gè)基本的草稿是有效的,所以我已經(jīng)消除了任何權(quán)限問題。我在這里使用代碼作為靈感,但無法讓它發(fā)揮作用。這是我到目前為止所做的:public String generateGmailDraft(EmailRequestDto emailRequestDto, String quoteId)         throws MessagingException, IOException, GeneralSecurityException {    // The attachment is a PDF file    AttachmentDto lastQuoteData = getLastQuotePdfData(quoteId);    MimeMessage email = createMimeMessage(emailRequestDto, lastQuoteData);    Message messageWithEmail = createMessageWithEmail(email);    Draft draft = new Draft();    draft.setMessage(messageWithEmail);    // this works    Gmail gmail = gmail(googleGmailCredentialProperties);    log.debug("attempting to send mail");    draft = gmail.users().drafts().create(emailRequestDto.getFrom(), draft).execute();    log.debug("Draft id: {}", draft.getMessage().getId());    log.debug(draft.toPrettyString());    return draft.getMessage().getId();}從 Google 示例中,我創(chuàng)建了一個(gè) MIME 消息,但這可能是問題所在:/** * Create a MimeMessage using the parameters provided * @return the MimeMessage to be used to send email * @throws MessagingException */private MimeMessage createMimeMessage(EmailRequestDto requestDto, AttachmentDto attachment)        throws MessagingException, IOException {    Properties props = new Properties();    Session session = Session.getDefaultInstance(props, null);    MimeMessage email = new MimeMessage(session);    email.setFrom(new InternetAddress(requestDto.getFrom()));    email.addRecipient(javax.mail.Message.RecipientType.TO, ew InternetAddress(requestDto.getTo()));    email.setSubject(requestDto.getSubject());    BodyPart messageBodyPart = new MimeBodyPart();    messageBodyPart.setHeader("Content-Type", "multipart/alternative");}
查看完整描述

1 回答

?
慕工程0101907

TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊

嘗試與此類似的操作:


private MimeMessage createEmailWithAttachment(String to,

        String subject,

        String bodyText,

        File file) throws MessagingException, IOException {

    Properties props = new Properties();

    Session session = Session.getDefaultInstance(props, null);


    MimeMessage email = new MimeMessage(session);


    email.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));

    email.setSubject(subject);


    MimeBodyPart mimeBodyPart = new MimeBodyPart();

    mimeBodyPart.setContent(bodyText, "text/plain");


    Multipart multipart = new MimeMultipart();

    multipart.addBodyPart(mimeBodyPart);


    mimeBodyPart = new MimeBodyPart();

    DataSource source = new FileDataSource(file);


    mimeBodyPart.setDataHandler(new DataHandler(source));

    mimeBodyPart.setFileName(file.getName());


    multipart.addBodyPart(mimeBodyPart);

    email.setContent(multipart);


    return email;

}


查看完整回答
反對(duì) 回復(fù) 2023-04-26
  • 1 回答
  • 0 關(guān)注
  • 171 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)