How to add the list of Cc and Bcc recipients in sendrawemail (java). I'm just adding all the recipients to one list and sending the mail. There is no separate method to set Cc and Bcc for SendRawEmailRequest.
Is there any way to set object of Destination type?
List<String> receipients = new ArrayList<String>();
receipients.addAll(mailToRecipients);
receipients.addAll(mailCcRecipients);
receipients.addAll(mailBccRecipients);
SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage).withDestinations(receipients);
Regarding SendRawEmail, you should be able to differentiate To, Cc, and Bcc destinations by setting them in your raw message headers. If you don't explicitly specify destinations in the request object, the headers will be checked instead. If you do, the headers won't be checked.
Here's a great example regarding this problem that JustinC#AWS shared on the AWS forums:
Destinations: (empty)
To: A#example.com
Cc: B#example.com
Bcc: C#example.com
The above message will be sent to all three of A#, B#, C#example.com.
In contrast, if you send the following input:
Destinations: A#example.com
To: A#example.com
Cc: B#example.com
Bcc: C#example.com
That message will be delivered only to A#example.com.
Related
I am generating an email using sendgrid in my spring application . Everything is working fine but i am getting a verbiage below in the email saying like
"Do not reply to this message via e-mail. This address is automated and unattended"
Both FROM and TO are my organization ids .Is there anyway i can avoid that verbiage . Please help. Thanks.
Below is my email code
Value in emailContent is
"A new ticket has been created in your queue."
But the email i am receiving is
"A new ticket has been created in your queue. Do not reply to this message via e-mail. This address is automated and unattended."
Email from = new Email(fromDl);
Email to = new Email(toDl);
Content content = new Content("text/html", emailContent);
Mail mail = new Mail(from, subject, to, content);
SendGrid sg = new SendGrid(emailKey);
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
Normally SendGrid will not append anything to the contents of your email. However, you can set up an account level footer in your account mail settings.
To stop the appended content, remove the footer. Make sure that other emails you are sending don't miss out on that content too though.
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.
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);
}
Is there any way to add Recipient address using setHeader() like
message.setHeader("To:","mail#domain.com");
I tried the above one and it is not working. Please correct me if I am wrong.
I need an alternative for the following code:
InternetAddress mail_to = new InternetAddress("mail_id#domain.com","Name_of_recipient");
message.addRecipient(Message.RecipientType.TO, mail_to);
My requirement is to skip RFC822 email format check.
The header name is "To", without the colon.
But you're not going to get very far with an incorrectly formatted address. Even if JavaMail doesn't detect the error, the server most likely will.
I have read all the reference in stackoverflow. However, nothing matches in our goal. How can i use bcc in sendmail method in java?
According to the RFC for SMTP, RFC 2821 (link), it is not possible to send an email message without a To: header. (You cannot send an RCPT command without it, see section 3.3.)
As Dietrich mentions, that's not possible with the RFC. If the primary goal is to send to the bcc target email addresses, you could provide a dummy to email address (such as your own email address or a reply-to email), which would fulfill that technicality while still allowing you to send the email to the desired bcc targets.
msg.addRecipient(Message.RecipientType.BCC, new InternetAddress("joe#example.com"));
By default, JavaMail collects all the recipients specified on the Message object, including Bcc recipients, and uses them in the RCPT command to the SMTP server. The Bcc recipients won't show up in the message headers, however (which is the whole point of Bcc).