SendGrid (자바)를 통해 Google App Engine에서 보낸 이메일에 첨부 파일을 추가하는 방법은 무엇입니까?

yonojoy

Google 정보따라 SendGrid를 통해 App Engine에서 이메일을 보냈습니다. 이것은 SendGrid 용 Java 라이브러리 와 제공된 예제 코드 사용하여 제대로 작동합니다 .

import packageName.Sendgrid;

Sendgrid mail = new Sendgrid("<sendgrid_username>","<sendgrid_password>");
mail.setTo("[email protected]")
    .setFrom("[email protected]")
    .setSubject("Subject goes here")
    .setText("Hello World!")
mail.send();

하지만 이제 파일을 첨부해야합니다. 어떻게 할 수 있습니까? 라이브러리addAttachment 에서-함수 또는 이와 유사한 것을 찾을 수 없습니다 .sendgrid-google-java

Serge Hendrickx

특정 Google이 아닌 Appengine 에서 SendGrid Java API사용합니다 . 예를 들면 다음과 같습니다.

import com.sendgrid.*;

public class SendGridExample {
  public static void main(String[] args) {
    SendGrid sendgrid = new SendGrid("SENDGRID_APIKEY");

    SendGrid.Email email = new SendGrid.Email();

    email.addTo("[email protected]");
    email.setFrom("[email protected]");
    email.setSubject("Sending with SendGrid is Fun");
    email.setHtml("and easy to do anywhere, even with Java");

    SendGrid.Response response = sendgrid.send(email);
  }
}

https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/java.html

다음 세 가지 기능 중 하나를 사용하여이 이메일 객체에 첨부 파일을 추가 할 수 있습니다.

    public Email addAttachment(String name, File file) throws IOException, FileNotFoundException {
        return this.addAttachment(name, new FileInputStream(file));
    }

    public Email addAttachment(String name, String file) throws IOException {
        return this.addAttachment(name, new ByteArrayInputStream(file.getBytes()));
    }

    public Email addAttachment(String name, InputStream file) throws IOException {
        this.attachments.put(name, file);
        return this;
    }

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관