Sending same emails to many addresses - java

Hi
I have to send am mail(like an notification) to all the persons who fulfill some criteria.
The mail id will be taken from the database and sent the mail
Where should I look for the implementation in JAVA so that I can sent the a mail to many person.
Thanks

Have a look at the javax.mail Package
Links:
http://java.sun.com/products/javamail/javadocs/javax/mail/Message.html#addRecipient%28javax.mail.Message.RecipientType,%20javax.mail.Address%29
And as Message.RecipientType you should use Message.RecipientType.BCC to not showing the every address to every recipient
Google Keywords: Java Mail BCC

This is how to send email using Java: http://www.javabeat.net/tips/33-sending-mail-from-java.html
To send email to many addresses, just send the same email with different 'to' address

There are several ways to go about this. Assuming you know how to query the database to get the mail and recipients and how to actually send (a single) mail - it's really up to preferences.
Personally I prefer to simply put all recipients in "the BCC-field" and then actually send the mail to a dummy address or my own. That way none of the recipients will be disclosed to the others. If that is not an issue - just put 'em all in the "To-field".
(if in fact querying database and sending mail is the real issue - I'm sure there are quite a few references on this site)

The Apache Commons Email library in an excellent Java API for sending Email. You can use the approach taken by #mbanzon to send the list by adding Bcc fields.

Related

New to Email Parser in Java, facing issue when reading the subject

How do I read the original subject of the kick back email received from the mail delivery system.
I am doing it this way: messageSubject = message.getSubject(); which actually returns the wrong one i.e ”Delivery status notification” (this one I can see under subject of view message details of kick back email).
It is normal for a "bounce" email that you get in response to an email that cannot be delivered to have a different subject to the email that you sent. The original email may be included as an attachment to the notification.
The responses that you get in this scenario are not standardized and vary from one mail server (MTA) to another. If you are going to process them automatically, you will need to understand the structure of the responses you are getting from your MTA and potentially the remote MTA that are bouncing the emails.
You should probably start by looking at the bounce emails in your email to get an idea of their structure.

How do you send emails in android from any email address?

Hi I was following the answer to this question:
Sending Email in Android using JavaMail API without using the default/built-in app
but setting the sender in the method sendMail does not work.
I would like to be able to send mail from different addresses such as support#example.com, sales#example.com, etc... so that way when people reply to the emails they go to the correct addresses.
Edit: By does not work I mean whenever I get an email it is always from the account that you sign into using:
GMailSender sender = new GMailSender("username#gmail.com", "password");
and not the sender field that you fill out in the sendMail method:
sender.sendMail("This is Subject",
"This is Body",
"sender#gmail.com",
"recipiant#yahoo.com");
What do you mean "does not work"? If you don't provide full details, no-one can help you.
The chances are that the SMTP mail server you are using is blocking you from spoofing email addresses you do not own, and for good reason. It sounds like you are writing an app that will do things the user probably does not want it to do.
You should have your own email server set up for this. It will direct the email through your server, which will send the email under whatever email alias you like. That way the details will not be "incorrect" because the user should have an account with you which is logged into your server to send the email.

is it possible to hide email adress in javax.mail.MimeMessage?

I'm using the following code to create and send an email to someTo#bla.com:
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress("someone#bla.com", "From Me"));
And when I receive the mail I see (in outlook, for example) : From Me <someone#bla.com>
Is it possible to hide the email address? I would like to see the full email address only when the receiver hits "Replay" but not before.
No, there is no way to hide the address of the sender when you (your program) is the sender. Some email clients may have the ability to do that, but in general it is probably a bad practice because it makes it harder to tell who sent the email, making it easier for spamers and phishers.
One way you could hide your email address would be to use a proxy service that sends and receives emails on your behalf and acts as a simple forwarding proxy (this is what craigslist does), but that starts to drift into the real of sketchy practices.
Short answer is no. That is a configuration option usually on the users mail client. It is there to help users avoid PHISHING scams and other unscrupulous email attacks.

GMAIL: Send one email with multiple addresses or sending multiple emails. Which one is better?

My web app using JMS to send mail via GMAIL as my SMTP server. I need to send out email to every people in my group (20 - 50 people), does GMAIL allow to send this many email in short amount of time? And if so, can I get around with either sending one email with multiple addesses or sending multiple email with one address.
Think about this:
If you send one email, the mail server does the work sending a copy to each recipient.
If you send 20 emails, your code does all the work, sending 20 copies over the network to the email server.
You may want to use bcc: for the recipients if you don't want every recipient to see the address of every other.
The only reason you would want to send multiple messages is if you want to customize the message, such as
Hello <username>
blah blah blah

Search email inbox using javax.mail

I was trying to see if there was a way to search an email inbox from javax.mail. Say I wanted to send a query and have the it return emails to us. Can we parse returned HTML and extract data. Also, if the above is possible how would I "translate" those messages returned by that server to POP3 messages? E.g. we have extracted:
Subject: Foo
Body: Bar
but to open same message using POP3 I need to know it's POP3 uid, or number. I don't think we'll be able to get UID but perhaps we can figure out the number.
I guess the question is:
Can I send a query to email server (such as Hotmail or Yahoo) and get returned emails?
Unfortunately, the POP3 protocol doesn't support that. It is not like SQL or so. You need to mirror the complete mailbox yourself in some kind of a datastore (SQL database?) and execute the search on that. You can eventually keep/cache the data so that you don't need to retrieve the whole inbox everytime, but only the unread items.

Categories