public static void main(String[] args) throws SendGridException { SendGrid sendgrid = new SendGrid(SENDGRID_API_KEY); SendGrid.Email email = new SendGrid.Email(); email.addTo(TO_EMAIL); email.setFrom(SENDGRID_SENDER); email.setSubject("This is a test email"); email.setText("Example text body."); SendGrid.Response response = sendgrid.send(email); if (response.getCode() != 200) { System.out.print(String.format("An error occured: %s", response.getMessage())); return; } System.out.print("Email sent."); }
@Override protected Void doInBackground(Void... params) { try { SendGrid sendgrid = new SendGrid(SENDGRID_USERNAME, SENDGRID_PASSWORD); SendGrid.Email email = new SendGrid.Email(); // Get values from edit text to compose email // TODO: Validate edit texts email.addTo(mTo); email.setFrom(mFrom); email.setSubject(mSubject); email.setText(mText); // Attach image if (mUri != null) { email.addAttachment(mAttachmentName, mAppContext.getContentResolver().openInputStream(mUri)); } // Send email, execute http request SendGrid.Response response = sendgrid.send(email); mMsgResponse = response.getMessage(); Log.d("SendAppExample", mMsgResponse); } catch (SendGridException | IOException e) { Log.e("SendAppExample", e.toString()); } return null; }
private void send(String recipient, Email email) { if (StringUtils.isBlank(cfg.getIdentity().getFrom())) { throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " + "You must set a value for notifications to work"); } try { email.addTo(recipient); email.setFrom(cfg.getIdentity().getFrom()); email.setFromName(cfg.getIdentity().getName()); Response response = sendgrid.send(email); if (response.getStatus()) { log.info("Successfully sent email to {} using SendGrid", recipient); } else { throw new RuntimeException("Error sending via SendGrid to " + recipient + ": " + response.getMessage()); } } catch (SendGridException e) { throw new RuntimeException("Unable to send e-mail invite via SendGrid to " + recipient, e); } }
public Email addTo(String to, String name) { this.addTo(to); return this.addToName(name); }
SendGrid sendgrid = new SendGrid("YOUR_API_KEY_HERE"); SendGrid.Email welcomeMail = new SendGrid.Email(); welcomeMail.addTo(emailAddress); welcomeMail.addToName("User-san"); welcomeMail.setFrom("welcome@example.com"); welcomeMail.setSubject("Welcome to Example!"); welcomeMail.setText("Thank you for your interest in Example.com! It is still in Beta at the moment but there are a number of exciting features planned. Tell us what you'd like to see."); try { SendGrid.Response response = sendgrid.send(welcomeMail); System.out.println(response.getMessage()); } catch (SendGridException sge) { sge.printStackTrace(); }
SendGrid sendgrid = new SendGrid(Constants.SENDGRID_API_KEY); SendGrid.Email email = new SendGrid.Email(); email.addTo("recipient@gmail.com"); email.setFrom("whatever@whatever.com"); email.setFromName("Whatever"); email.setSubject(...); ....
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("test@sendgrid.com"); email.setFrom("you@youremail.com"); email.setSubject("Sending with SendGrid is Fun"); email.setHtml("and easy to do anywhere, even with Java"); SendGrid.Response response = sendgrid.send(email); } }