Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,23 @@ import java.io.File;
SendGrid sendgrid = new SendGrid("sendgrid_username", "sendgrid_password");
sendgrid.addTo("example@example.com");
...
sendgrid.addFile(new File("../path/to/file.txt"));
sendgrid.addAttachment(new SendGrid.Attachment(new File("../path/to/file.txt")));
```

If you need to add files from an InputStream (maybe you're on Google App Engine), here is how.
If you need to add files from an InputStream (maybe you're on Google App Engine and have the contents in a byte array), here is how.

```java
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import java.io.ByteArrayInputStream;

SendGrid sendgrid = new SendGrid("sendgrid_username", "sendgrid_password");
sendgrid.addTo("example@example.com");
...
try {
InputStream is = new FileInputStream("c://filename");
is.close();
byte[] contents = somehowGenerateAttachmentContents();

SendGrid.Attachment attachment1 = new SendGrid.Attachment("filename.txt", is);
sendgrid.addFile(attachment1);
SendGrid.Attachment attachment1 = new SendGrid.Attachment("Invoice.pdf", new ByteArrayInputStream(contents));
sendgrid.addAttachment(attachment1);

sendgrid.send();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
```

### Bcc
Expand Down