How do I customise the Unsubscribe link in SendGrid? - java

I wish customise the position of the default Unsubscribe link that is sent by Sendgrid.
I have configured Unsubscribe groups in sendgrid and I am sending groupId with ASM, I do see the Unsubscribe from this List| Manage Email Preferences link, but the thing is, this link is directly appended to the body of the email thus making it difficult for the receiver to understand whether it is a part of the email or not, is there a way to customise this link so that it at least looks as a separate part of the email content?
ASM asmInst = new ASM();
asmInst.setGroupId(mailGroupId);
mail.setASM(asmInst);
int[] groupsToDisplay = {mailGroupId};
asmInst.setGroupsToDisplay(groupsToDisplay);
mail.setTemplateId("d-
848281f0ab8f45a7bc0e1690442a8803");
}
above is my java code, here the mail object refers to instance of Mail from com.sendgrid.Mail and the object already has subject, recipient, email body, etc. If I set the template id as above, the email received by the recipient does not contain any subject, or email body, it only has the subscribe module that is configured in the dynamic templates. Here is a screenshot of the email received.
If I don't set the templateId, the email received is proper but the unsubscribe links are directly attached to the email body. Here is the email without template

Related

Using Gmail aliases to link mail replies to application content

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.

Add news email to mailjet by the REST API

I making one application that can send different email, but the email address depends of the user. I'm using mailjet to do this, after reading the doc, it's seem that i have to add every email for have the right to send email from this address, but this address are not generate by me (they are gmail, toto, etc)
I already use the Java API of mailjet to add user, and this part is working fine
But my problem is when the validation email arrive, and the person follow the link, mailjet ask to login, but he do not know what to do, because normally is my own account, i only what to add their email address to have the right to send email with them.
So the question, is how i can add email address (from gmail, yahoo...) and activate the user, without the login part.
Thanks for having choosen Mailjet to power your email!
I believe the right setup for you would be to use the Sender header. It will allow you to send email from a unique (or multiple, depending of your setup) pre-validated sender email addresses while setting the From email header to the email you want to send the email from.
In your recipients Inbox, it will display as foobar#gmail.com via notifications#mycompany.com, indicating clearly to the recipient that you're sending on behalf of foobar#gmail.com. This way, you won't be forced to validate each email address, just ones you'll
This is a very common setup for resellers and platforms sending a lot of personalised email.
In order to achieve this, please contact our [support team](https://app.mailjet.com/support] with a reference to our discussion here so they know what we're talking about. They'll guide you to the implementation it.
Hope it helps,
Best.

java mail - getting message by message ID

I'm developing Android mail client. I need to build a "conversation" structure for every email message. I use the
IMAPMessage.getInReplyTo()
method that returns the Message ID of message which the message is a reply to. Unfortunatelly there seems to be no easy way to obtain message from
IMAPFolder
using its message ID. It is only possible to get the message by its UID. Is there an easy way to get the IMAP message by its Message ID?
You can use the IMAPFolder's search method like this:
SearchTerm searchTerm = new MessageIDTerm(messageId);
Message[] messages = imapFolder.search(searchTerm);
See the docs for the IMAPFolder's search method here:
https://javaee.github.io/javamail/docs/api/com/sun/mail/imap/IMAPFolder.html#search-javax.mail.search.SearchTerm-
and for the MessageIDTerm class here:
https://javaee.github.io/javamail/docs/api/javax/mail/search/MessageIDTerm.html
unfortunately there is no straight forward solution... May be what you can try is to maintain an internal structure with body structures of all the mail ids and then perform a one on one Message-ID check and obtain the UID of mail. Anyways you would be doing it, in order to show the Maillist. Add a new logic to map the message-ids as well.

Java Mail API: Find if a mail is forwarded mail or a reply to another mail

I have a very special requirement
I am using Java Mail API to access a user's Inbox. You can say its like a service inbox for complaints. User registers a complaint by sending an email to this address. I fetch every email from Inbox and create a new complaint. My problem is that I don't want to create unnecessary complaints for reply or forwarded emails. Is there a way to find out that.
Most email clients add Re: or Fwd: to the subject line, but I wouldn't rely on that to determine whether an email is a reply or forwarded text; for example, a German mailclient might put Betr.: in front of the original subject.
Instead, you might want to look at the In-Reply-To: header and/or the References: header. See RFC 4021 for detailed information on those headers.
You can retrieve the headers from a Message by calling the getHeader(java.lang.String) method.
Reading the email header might help, see http://javamail.kenai.com/nonav/javadocs/javax/mail/Part.html#getAllHeaders(). In case of replies, the message header would include:
In-Reply-To: Message-ID of the message that this is a reply to
In case of a forwarded message, selected headers might be preserved. Not as straight-forward as the previous case, but it might still be possible to determine if it was a forwarded message. Refer to http://en.wikipedia.org/wiki/Email_forwarding#Manual_client-based_forwarding for details.

Some questions related to implementation of image inside email signature?

i need to implement the email signature with image.As of now we only support the text in email signature which is already working.i need to provide the functionality
where i can insert the image inside mail signature. i can send the email to user within myapplication and also to user on external mail domain like gmail,yahoo etc. When
mail is sent to some user with in my application system, system makes entryt o DB and when receiver receives in inbox (which internally read the mail from db). Now if user
send the mail to external user on gmail it makes use of javax mail api . Similary i can receive the email from external mail domains(gmail,yahoo etc) Now i have
few questions based on tis requirement:-
1)Is there any standard for how the external mail domains like gmail send the image inside signature to another domains like (my application mail domain)?
Another point related to it gmail user can have two images ,one for signature and another image inside body. How will i determine which image belongs to
signature? Is there any defined property for that?
2)Also not able to make out what is the best/consistent approach to send(whether to internal application user or external mail domain user ) the email signature containing
image so that it renders correctly when user receives it?
what I had in my mind for point 2:- i earlier thought i can use solution suggested at How to display an image in jsp?. where
with tag <.img src="/getImage.action?imageId=123">, i can fetch the image from db in action class or servlet and return. But keeping in mind
once i send the mail to the user on gmail , he will not be able to access the servlet.So this approach does not seems to fit in requirement.
Then i came across the another great stackoverflow link base64 encoded images in email signatures where
solution by Tim Medora looked great but again the comment below the solution Gmail doesn't seem to support it again ended my Folks
really i think i should be done if mail domain like gmail,yahoo support the solution suggested by because in that case i can send image as base64 string instead
of image as attachment.
Folks would be really grateful if you can provide me some pointer/approach regarding both points 1 and 2
To include images in the email message, first you have to include the images as MIME attachments in the email. Each of these attachments must have a "Content-ID" header.
--f46d0444ea0d6991ba04b91c92e6
Content-Type: image/gif; name="theImage.gif"
Content-Transfer-Encoding: base64
Content-ID: <theImage#abcd>
[base64 string]
--f46d0444ea0d6991ba04b91c92e6--
2) Then, in the email message, include the Content-ID in the src attribute of the <img> tag.
<img src="cid:theImage#abcd" />
For Gmail to see the embedded image from byte array, I posted an answer on another similar question which is to use ByteArrayDataSource and embed it to the HtmlEmail. Here's the code snippet:
import javax.mail.util.ByteArrayDataSource;
import org.apache.commons.mail.ImageHtmlEmail;
...
ImageHtmlEmail email = new ImageHtmlEmail();
byte[] qrImageBytes = createQRCode(); // get your image byte array
ByteArrayDataSource qrImageDataSource = new ByteArrayDataSource(qrImageBytes, "image/png");
String contentId = email.embed(qrImageDataSource, "QR Image");

Categories

Resources