I am using SendGrid for my transactional mails. When I just send the mail without using template using SendGrid JAVA classes, it works fine. However when I try to send it using the sendgrid template, it does not send a mail. My code is,
SendGrid sendGrid = new SendGrid(sendGridAPIKey);
SendGrid.Email sendGridMail = new SendGrid.Email();
sendGridMail.setTo(new String[] {email});
sendGridMail.setFrom("info#from.com");
sendGridMail.setSubject("Welcome to our portal");
sendGridMail.setText("Welcome Text");
sendGridMail.addFilter("templates", "enable", "1");
sendGridMail.addFilter("templates", "template_id", "TEMPLATE_ID");
sendGridMail.addSubstitution(":firstName", new String[] { firstName });
sendGridMail.addSubstitution(":email", new String[] { email });
SendGrid.Response response = sendGrid.send(sendGridMail);
The SendGrid template (with id TEMPLATE_ID) content looks as below,
Dear -firstName-,
Welcome to our portal. Your username is -email- and password is xxxxx. Please login to our portal with these credentials.
Thanks.
I am not sure what is going wrong as there is no exception thrown, the calls succeed, but the mail is not received.
Is there any way to track the failures in SendGrid admin console?
Is there any setting I need to do to get this working?
Is there anything wrong in the code I am using?
Any help would be greatly appreciated.
Thanks in advance,
Kari...
Related
I'm trying to integrate Twilio email verification in my application. Here's the code:
public EmailVerificationDto sendVerificationEmail(String recipient) {
Verification verification = Verification.creator(
PATH_SERVICE_SID,
recipient,
"email")
.setChannelConfiguration(
new HashMap<>() {{
put("template_id", TEMPLATE_ID);
put("from", SENDER_EMAIL);
put("from_name", "Puggle");
}})
.create();
return new EmailVerificationDto(
verification.getTo(),
verification.getSid(),
verification.getStatus(),
verification.getDateCreated().toLocalDate()
);
}
I can see the email on the dashboard but it's stuck on processing:
I got the same problem, seems like SendGrid have problem with people using the service for fraudulent use so you need to get verified first. On the top of the page, you probably have a message saying that you need to get verified. You will need to fill a form, then they will contact you via email to gather some more information and accept or deny your access to the service.
I tried to use Java mail API to send a gmail with starred. I read in many places and I added code as follows:-
if (mailHighPriority) {
msg.setHeader("X-Priority", "1");
msg.setHeader("Importance", "high");
msg.setHeader("priority", "Urgent");
msg.setHeader("x-msmail-priority", "high");
}
However, I am not able to set the Gmail as starred. Is there any other option for this? Thanks
STARRED is a label used by gmail. You can't set a label when sending a mail.
You need to set up a filtering rule or use the gmail api to apply labels to messages.
I am working on sending emails through ews.
In some scenarios, users wants to be able to get an email (parentEmail) with another email (emailToAttach) attached. This emailToAttach is retrieved from the sent folder and then attached to the parentEmail.
However, I am getting a stackoverflow error when I am trying to do the following at setSubject:
EmailMessage parentEmailMessage = new EmailMessage(exchangeService)
ItemAttachment attachment = parentEmailMessage.attachments.
<EmailMessage>addItemAttachment(Item)
attachment.setName(emailToAttach.subject)
attachment.item.setSubject(emailToAttach.subject)
attachment.item.setMimeContent(emailToAttach.mimeContent)
Can anyone help figure out why is the stack over flow error produced?
I have the following use case in my app:
When a specific event happens in the app all interested users should be notified by email. Then if a user replies to the email, his reply should be shown in the event page in the app.
My initial idea was to create a temp mail alias of the main notification email every time when an event happens and send the notification email with that alias set in the Reply-To header. Then if someone replies to that mail by using the alias (let's say csa123423#mydomain.com) I can figure out which event this reply refers to.
It turned out that Spring's JavaMailSender doesn't provide a way to use aliases, so I tried with Gmail API. As far as I understood creating a Gmail alias means actually setting an already existing email in your domain as an alias for another already existing email in that domain. So the Java code to achieve this using Directory API and Gmail API would look like this:
User newUser = new User();
UserName userName = new UserName();
userName.setGivenName("xsd");
userName.setFamilyName("ewrewr");
newUser.setPrimaryEmail("bbb34262bb45#mydomain.com");
newUser.setPassword("12345");
newUser.setName(userName);
User result = directoryService.users().insert(newUser).execute();
SendAs sendAs = new SendAs().setSendAsEmail("bbb34262bb45#mydomain.com").setReplyToAddress("bbb34262bb45#mydomain.com").setDisplayName("My name").setTreatAsAlias(true);
SendAs sendAsResult = gmailService.users().settings().sendAs().create(user, sendAs).execute();
MimeMessage emailContent = createEmail("mymail#gmail.com", "bbb34262bb45#mydomain.com", "Test from app", "Test body");
Message message = createMessageWithEmail(emailContent);
message = gmailService.users().messages().send(user, message).execute();
But as far as I know there are some limits on the number of accounts you can create per domain/account and also Google would charge more for this.
Is there another easier way to create aliases in Gmail? Or is there another approach to achieve the desired functionality (linking mail replies to application content) without using mail aliases?
Try leveraging '+' functionality given by Gmail for creating temporary aliases.
The basic idea is if my email id is xyz#gmail.com, I can send/receive an email with xyz+1#gmail.com or xyz+anything_here#gmail.com and it will work like a charm.
You can utilize this by keeping the alias/unique-id after the '+' in the Gmail id and then parse this alias easily in your application.
Our application uses javax.mail.MimeMessage, we are written this code
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress("mail#xyz.com", "XYZ"));
From section changing work in gmail and yahoo but not working outlook,
can any tell reason for this.
You need to add msg.setSender(new InternetAddress(...));