Our application send emails automatically, and I need those emails to be grouped in threads, so the user have them organized in their mailboxes. These emails could have different subjects as well. For example:
Issue 93 created
Issue 93 description changed
Issue 93 assignee changed
Issue 94 created
Issue 94 closed
I'm trying to set the "In-Reply-To" header of every child email to point to the parent mail Message-ID. So, every time a new issue is created, and the first mail is sent, I will save its Message-ID. When a new email related to the issue is going to be sent, I will add a "In-Reply-To" header, pointing to the saved Message-ID.
My code looks like this:
Message message = new CustomMessage(session, parentMessageId);
message.setFrom(new InternetAddress("from#mycompany.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("to#customer.com"));
message.setSubject("Issue " + id + " " + actionPerformed);
message.setText(content);
message.saveChanges();
Transport.send(message);
Class CustomMessage looks like this:
public class CustomMessage extends MimeMessage {
private String inReplyTo;
public CustomMessage(Session session, String inReplyTo) {
super(session);
this.inReplyTo = inReplyTo;
}
#Override
public void saveChanges() throws MessagingException {
if (inReplyTo != null) {
// This messageID is something like "<51228289.0.1459073465571.JavaMail.admin#mycompany.com>" including <>
setHeader("In-Reply-To", inReplyTo);
}
}
}
The problem is the email is sent, but is not grouped in threads. I have noticed that they are grouped correctly if they have the same subject, but I need different subjects for every email.
Is this actually possible with different subjects? Do I need to use a different strategy?
Thanks
It depends on the "threading" algorithm used by whichever mail reader is being used. As the creator of the messages you don't have absolute control over how they're displayed.
Related
currently I'm creating an email service for my hobby project for newly signed up users. This is the relevant part of the code, which causes me some headache:
private Message createEmail(String firstName, String password, String email) throws MessagingException {
Message message = new MimeMessage(getEmailSession());
message.setFrom(new InternetAddress(FROM_EMAIL));
message.setRecipient(Message.RecipientType.TO, InternetAddress.parse(email, false)[0]);
message.setRecipient(Message.RecipientType.CC, InternetAddress.parse(CC_EMAIL, false)[0]);
message.setSubject(EMAIL_SUBJECT);
message.setText("Hello " + firstName + ", \n \n Your new account password is: " + password + "\n \n " +
"The support team");
message.setSentDate(new Date());
message.saveChanges();
return message;
}
I have two problems with this line message.setRecipient(Message.RecipientType.TO, InternetAddress.parse(email, false)[0]); (and of course the same problem with the next line below it):
On the internet, if I google after it, everywhere it is used like this:
message.setRecipient(Message.RecipientType.TO, InternetAddress.parse(email, false);
so, without the indexing. But if I remove the indexing, I get an IDE error, which says, that the function requires a type of Address, but it has got InternetAddress[], an array. That's why I put the indexing.
But if I leave the indexing and run the app and register a new user, I get the error in the console: Index 0 out of bounds for length 0. Obviously, the InternetAddress[] array is empty. But why?
What exactly is going on here?
Looking at the docs, it should be new InternetAddress(String, boolean), which
Parse[s] the given string and create[s] an InternetAddress.
instead of InternetAddress.parse(String, boolean), which
Parse[s] the given sequence of addresses into InternetAddress objects.
I have a code that fetches conversations and the messages inside them (a specific number of pages). It works most of the time, but for certain conversations it throws an exception, such as:
Exception in thread "main" com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Unknown path components: /[id of the message]/messages (code 2500, subcode null)
at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:1192)
at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:1118)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:1059)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:970)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:932)
at com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:356)
at test.Test.main(Test.java:40)
After debugging I found the ID that doesn't work and tried to access it from graph-api, which results in an "unknown path components" error. I also attempted to manually find the conversation in me/conversations and click the next page link in the graph api explorer which also lead to the same error.
Is there a different way to retrieve a conversation than by ID? And if not, could someone show me an example to verify first if the conversation ID is valid, so if there are conversations I can't retrieve I could skip them instead of getting an error. Here's my current code:
Connection<Conversation> fetchedConversations = fbClient.fetchConnection("me/Conversations", Conversation.class);
int pageCnt = 2;
for (List<Conversation> conversationPage : fetchedConversations) {
for (Conversation aConversation : conversationPage) {
String id = aConversation.getId();
//The line of code which causes the exception
Connection<Message> messages = fbClient.fetchConnection(id + "/messages", Message.class, Parameter.with("fields", "message,created_time,from,id"));
int tempCnt = 0;
for (List<Message> messagePage : messages) {
for (Message msg : messagePage) {
System.out.println(msg.getFrom().getName());
System.out.println(msg.getMessage());
}
if (tempCnt == pageCnt) {
break;
}
tempCnt++;
}
}
}
Thanks in advance!
Update: Surrounded the problematic part with a try catch as a temporary solution, also counted the number of occurrences and it only effects 3 out of 53 conversations. I also printed all the IDs, and it seems that these 3 IDs are the only ones that contain a "/" symbol, I'm guessing it has something to do with the exception.
The IDs that work look something like this: t_[text] (sometimes a "." or a ":" symbol) and the ones that cause an exception are always t_[text]/[text]
conv_id/messages is not a valid graph api call.
messages is a field of conversation.
Here is what you do (single call to api):
Connection<Conversation> conversations = facebookClient.fetchConnection("me/conversations", Conversation.class);
for (Conversation conv : conversations.getData()) {
// To get list of messages for given conversation
LinkedList<Message> allConvMessagesStorage = new LinkedList<Message>();
Connection<Message> messages25 = facebookClient.fetchConnection(conv.getId()+"/messages", Message.class);
//Add messages returned
allConvMessagesStorage.addAll(messages25.getData());
//Check if there is next page to fetch
boolean progress = messages25.hasNext();
while(progress){
messages25 = facebookClient.fetchConnectionPage(messages25.getNextPageUrl(), Message.class);
//Append next page of messages
allConvMessagesStorage.addAll(messages25.getData());
progress = messages25.hasNext();
}
}
Google provides the following code to get a gmail draft
public static Draft getDraft(Gmail service, String userId, String draftId)
throws IOException {
Draft draft = service.users().drafts().get(userId, draftId).execute();
Message message = draft.getMessage();
System.out.println("Draft id: " + draft.getId() + "\nDraft Message:\n"
+ message.toPrettyString());
return draft;}
My question is : Can I get a MimeMessage from the Message? If I could, I would update this MimeMessage with multiple attachments. Or if anyone else knows how to update a draft with multiple attachments, please advice.
I am attempting to create new Interactions programmatically on Genesys Platform SDK 8.5 for Java.
I use the example on the API reference
public void createInteraction(String ixnType, String ixnSubtype, String queue) throws Exception
{
RequestSubmit req = RequestSubmit.create();
req.setInteractionType(ixnType);
req.setInteractionSubtype(ixnSubtype);
req.setQueue(queue);
req.setMediaType("email");
Message response = mPMService.getProtocol("IxnSrv").request(req);
if(response == null || response.messageId() != EventAck.ID) {
// For this sample, no error handling is implemented
return;
}
EventAck event = (EventAck)response;
mInteractionId = event.getExtension().getString("InteractionId");
}
However, this gives me an Unsupported protocol element error.
'EventError' (126) attributes:
attr_error_desc [str] = "Unsupported protocol element"
attr_ref_id [int] = 2
attr_error_code [int] = 4
How do I create a new Interaction programmatically?
Interaction server should be connected with ClientType as either MediaServer or AgentApplication for this request(RequestSubmit).
First of all, you must open your protocol as Media Server. After that you must submit your interaction to interaction server.
Firstly your protocol config must be like this;
interactionServerConfiguration.ClientName = "TestClient";
interactionServerConfiguration.ClientType = InteractionClient.MediaServer;
// Register this connection configuration with Protocol Manager
protocolManagementService.Register(interactionServerConfiguration);
Note : You must have MediaServer type application definition on your Configuration Env., you must see it in CME.
After open you connection to ixn server. You can submit your interaction what you like. Even you can create new type interaction just like i do. I did for our coopate sms system. Its name is not important. We defined it on our bussiness attribute, so our agent can send coopate 3rd party sms system from their agent desktop. Without new extension or new license :) Just tricked it system. Also genesys allows it. i know it because we are genesys official support team in our country :) (But agent seat license may be required depends on agent head count).
RequestSubmit request = RequestSubmit.Create();
request.TenantId = 1;
request.MediaType = "email";
request.Queue = c_inboundQueue;
request.InteractionType = "Inbound";
request.InteractionSubtype = "InboundNew";
// Prepare the message to send. It is inserted in the request as UserData
KeyValueCollection userData =
new KeyValueCollection();
// Prepare the message to send
userData.Add("Subject", "subject goes here");
request.UserData = userData; protocolManagementService[c_interactionServerConfigurationIdentifier].Send(request);
Turns out I needed to set ClientType to InteractionClient.ReportingEngine.
Hi i am trying to create meeting in lotus notes using java.i am able to send a meeting invite to the recipients.But when i send a meeting the options available to the chair and the recipients are the same.(options like accept,decline).But the options for the chair and the recipients should be different.can anyone please tell how to do this?
public DocumentKey save(final Session session, final Database db, boolean send,
String moveToFolder) throws NotesException, Io Exception {
//setBody(null);
Document doc = null;
RichTextItem rti = null;
try {
doc = db.createDocument();
db.getView(ServiceConstants.MEETINGS);
// Here i am setting all the properties for that document.
// I cant post that code as it has
// over 100 properties, so more than 100 lines of code
rti = doc.createRichTextItem(ServiceConstants.BODY);
rti.appendText(getBody());
if ((attachment != null) && (attachment.length > 0)) {
for (int i = 0; i < attachment.length; i++) {
attachment[i].save(rti);
}
}
doc.save(true, true, true);
if (send) {
doc.send();
}
if (!isBlank(moveToFolder)) {
doc.putInFolder(moveToFolder, true);
}
setKey(new DocumentKey(doc.getNoteID()));
} finally {
Helper.cleanupIfNeeded(rti);
Helper.cleanupIfNeeded(doc);
}
return getKey();
}
To successfully schedule a meeting, you need to follow the calendaring and scheduling schema
In short: A meeting has to be created in the chair's mail file and the invitations have to be responses (doc.MakeResponse(...)) to that main document and sent via mail. The "ApptUnid"- item ties them all together.
Read the documentation in the link, it is very good
If you are using Notes / Domino 9.0 or greater, you should consider using the lotus.domino.NotesCalendar interface and its related interfaces. These relatively new interfaces let you create, read and update calendar entries using iCalendar format.
Here's some sample code:
// Get the NotesCalendar object from the database
NotesCalendar notesCalendar = session.getCalendar(database);
if ( notesCalendar == null ) {
throw new Exception("Cannot open calendar.");
}
// Create a meeting in iCalendar format
String ical = iCalendarMeeting();
// Create the meeting on the Notes calendar
NotesCalendarEntry entry = notesCalendar.createEntry(ical);
This code creates an instance of NotesCalendar from an instance of Database. Then it gets the representation of a meeting in iCalendar format (the iCalendarMeeting method is not shown). Finally, it calls NotesCalendar.createEntry() to create the meeting. The createEntry method places the meeting on the organizer's calender and sends an invitation to all attendees.