I'm writing a program that has auto response in it. i.e. for example there is an user ad his email address would be user#domain.com, when ever someone writes an email to this address, there should be an auto response sent (Which I'm able to do it). but this should be sent from autoReply#domain.com(this is what I'm unable to know on how to do this). autoReply#domain.com is a shared mail box.
I'm using ews in my program and the below block of code is responsible to send the auto response.
private void replyToEmailWithURLs(ItemId itemId, List matchedKeyWords, String fromAddress) throws Exception {
EmailMessage message = EmailMessage.bind(service, itemId, new PropertySet(BasePropertySet.IdOnly));
ResponseMessage responseMessage = message.createReply(false);
message.getReplyTo().add(new EmailAddress("autoReply#domain.com"));
// Add autoReply in CC
responseMessage.getCcRecipients().add("autoReply#domain.com");
String responseUrls = getTheResponseUrlsFromJsonFile(matchedKeyWords, fromAddress);
responseMessage.setBodyPrefix(new MessageBody(BodyType.HTML, responseUrls));
responseMessage.sendAndSaveCopy();
message.setIsRead(true);
}
Here I tried to add a replyTo using message.getReplyTo().add(new EmailAddress("autoReply#domain.com"));, even this doesn't work.
I've seen a post here set reply-to address in outgoing email EWS , I was confused on the way it is working(basically given in c#), please let me know how can I get this done in Java.
Thanks
I'm not familiar with EWS, but apparently the standard JavaMail API supports setting From or the sender address.
Related
I am using EWS Java API to read and process emails. One such email contains few conversation and a MS Teams meeting information at the end. While reading such an email, the EmailMessage.getBody() returns only the MS Teams meeting information and all the other contents of the email body are ommitted. Sample code below:
EmailMessage message = EmailMessage.bind(service, new ItemId(item.get(nMessagePos).getId().getUniqueId()));
String emailBody = message.getBody().toString()
I tried setting the BodyType property to both HTML and Text and then fetched the body of the email but it still returns only the Meeting invite details.
Is there any specific reason for this and is there a way for me to get the complete email body?
I would try to enable tracing https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-trace-requests-responses-to-troubleshoot-ews-managed-api-applications or look at the actually soap responses your getting it could be a parsing issue at the client side (eg bug in the library). You could also try getting the Mimecontent of the Message instead and then parse back the body from that content. Something like EWSEditor might be useful for trying to diagnose what is going on it will show you what the responses look like and allow you to test mimecontent etc without needing to write any code https://github.com/dseph/EwsEditor/releases.
I am using amazon SES to send notification emails in my project. When a user replies back to this email I want to trigger some actions (like a ticket creation or update). Is it possible to know the contents or headers of the email for which user is replying ?
If the replying user's email system supports it (most do), you should receive an In-Reply-To: Header containing the message-id of the email you sent. If you kept that message (along with the message id) you can use this to retrieve original email.
Sometimes the Refereces: Header might be useful as well
I am facing one problem while extracting BCC address from incoming mail.
Here is the sample code that is used.
public EmailVO dumpEnvelope(Message m) throws Exception {
EmailVO emailVO = new EmailVO();
if ((addresses = m.getRecipients(Message.RecipientType.BCC)) != null) {
emailVO.setBcc(this.getAddresses(addresses, "BCC"));
}
}
I am getting null value in BCC.
While debugging I found BCC recipient's name in header field but I am not able to access that header.
Is this code issue or there is some specific setting while sending mail like not to include BCC fields?
The whole point of Bcc is that it's a blind carbon copy - the recipients don't get to see who was copied. You won't see Bcc fields in messages you receive. (Sometimes a Bcc'ed recipient will see the Bcc header in the messages they receive, but the other recipients will get a copy of the message without the Bcc. But I don't think many mailers do that anymore because it requires sending two different versions of the message.)
You can check your Message object which contains all the details about the mails.
As the BCC is the part of mail but also it will be hidden, but as per my knowledge you can retrieve the information from your mail headers.
Address[] addresses = m.getHeader("Your Header Name HERE");
This will give you all the details regarding your particular header tag in mails.
for e.g.
Address[] addresses = m.getHeader("Delivered-To");
This tag will give you all the information about the recipients of the mail, which will also include BCC.
you can also add your custom headers for mail.
addresses = m.getRecipients(Message.RecipientType.BCC);
returns an array of addresses. You can check the content in a for loop:
Address[] addresses = m.getRecipients(Message.RecipientType.BCC);
for(Address address : addresses){
System.out.println(address);
}
In simple word, whenever I will send mail to anyone (within same mail server) it should appears some fake email address i.e. fakemail#gmail.com but, when they reply to this mail, it should come to my actual email address that is realname#gmail.com.
Note: My both email addresses will use same domain name, but only difference will be fake and real username for that email. I needed for the privacy issue. So, that nobody can reply to my mail directly until I send any mail to them.
Ask your mail server administrator to setup an email forwarding for you.
This is not a Java specific question. What you are asking for is called an
Email alias, and is a standard functionality on mail servers.
You can use a fake "from:" field and a valid "reply-to:" field, but the only people that will be fooled by this are people who would not know how to send spam anyway.
Even if you can (see below) mask the From field, you are giving away your email address in the Reply-To field, so you are still revealing your email address. (And if you weren't, it wouldn't be possible to reply.) So go with #Anony-Mousse and find a proper solution.
Now, please note that there are two "from" fields: one in the SMTP envelope and another in the message data.
It is quite uncommon for current mail servers to let you fake the SMTP from, though it may be possible if the server is using raw SMTP without authorization.
You are more likely to be allowed to send an email with a custom "From" in the message body (which is the one mail clients display, unless you look att all headers). However, the mail server may require that it matches the user you authenticated as.
I have written a java program to send email via SMTP. I would like to know how I can request the user to add my email Id to his address-book/Contact list in his client automatically/manually. Is there a way for me to do it from within my java code. I would like this feature as my emails will not get listed as spam/junk. I am using javamail API.
Thank you,
Nagarajan
NOT POSSIBLE!! You can't do that ,Email will be just mail.Listing your emailid and other things(spam,junk mail) to be done by receiver only.Who receive they have to configure.