I've done quite a bit of research on this matter and I can't seem to come up with a solid solution to my problem.
I am developing a Java client application that (should) allow users to import their contacts from Mac Address Book by fetching them in a list format and allowing the user to select a subset/all and click a button that would send an "invitation" to these users.
I was able to grab contacts using the Rococoa Java framework but I am uncertain as to how to send email or if it is even possible. I realize there are security concerns with this, but I was able to accomplish this same task on Outlook for PC.
It seems that I may have to call an Applescript from my Java that manually opens Mac Mail Client and sends email using their default mail account setup.
I could be totally off-base here... should I even bother sending mail through the user's default Mail account? I wanted to avoid using a different mail server to avoid spam etc.
Any help would be appreciated, thank you for your time.
Matt
Here's an applescript to use Mail...
set emailSender to "sender#email.com>"
set emailTo to "recipient#email.com"
set theSubject to "The subject of the mail"
set theContent to "message body"
tell application "Mail"
set newMessage to make new outgoing message with properties {sender:emailSender, subject:theSubject, content:theContent, visible:true}
tell newMessage
make new to recipient at end of to recipients with properties {address:emailTo}
send
end tell
end tell
Another option, if you know the smtp information, is to use python. I made a command line program you can use. Find it here. There's example code to use it on the web page.
Related
I'm working on a project I'm Java with regards to outlook.
Here I'm able to do all the functions like Read a mail, write a mail, reply to a mail etc...
But now we've been thinking of taking it to the next level.
Our plan is as below.
We have an email address like info#myDomain.com, when ever an email is sent to this address, I need to reply them. Here basically customers send an email asking for some data, and we've the data available in our portal, and we just need to send it.
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
And this has to be done automatically when ever there is an email hit to this particular email address.
Couple of questions:
- should my machine be on the whole day to get this thing done.
- is there a way that a Java application can automatically monitor my inbox to see for this case match.
- Also, can I have this running in the bg.
Can someone please point me into the right direction/approach where can I can start working on this task.
Thanks
when ever an email is sent to this address, I need to reply them.
For this you need to monitor your email account fro incoming emails. Here is one of the way to do this
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
Once you receive an email (using above email monitoring approach), you need to call a method that sends the reply with above format
And this has to be done automatically when ever there is an email hit to this particular email address.
Above two steps accomplishes this task.
should my machine be on the whole day to get this thing done
Basically, you will need an application server (like tomcat) where your above java program is deployed. So, yes this server needs to be running and available all the time.
is there a way that a Java application can automatically monitor my inbox to see for this case match
Check point 1
Also, can I have this running in the bg
You can run tomcat as a service in windows (more info). It has many advantages, automatic startup on boot being the one. Similar implementations are also available for other OS.
So, in short, this can be accomplished. It is bit complex but not much difficult. Cheers
please how to test sending email without real server in java knowing that email is send in a project A and I want to test sending in project B
Email cannot be "sent" without an email server.
Email is modeled after a physical mail system, with a few changes. The "sending" is the equivlent to the dropping the letter off at a post office. It is not possible to do point-to-point email.
Email clients then open their "PO Box" or "Mailbox" on the server, and perhaps (it is optional) then downloads the mail into the local machine.
In fact, the "sending" of an email is a number of back-and-forth communication with the email server using SMTP. Basically sending an email consists of telling the server hello, then asking about it's capabilities, and eventually asking it to validate addresses and accept a body (and optionally attachments).
So, if you really need to send a mail to a product in project B, and you cannot rely on a standalone server, you need to create a server in project B.
I think that you should consider mocking the mail sending. Depending on the frameworks you use, you should be able to find a good way to do it. Here is a blog illustrating a possible mechanism: http://blog.nutpan.com/2012/03/mock-testing-for-java-mail.html?m=1
You can also consider using a mocking framework like easymock or mockito to test it.
I want to send a User an email or SMS to his SmartPhone when an Alert happens on his desktop App.
How can I send an email WITHOUT supplying my log-in credentials within the App?
using smtp I need to provide my credentials, but as this is for a published application that does not sound like a good idea.
I understand this is a very general question, but I am having trouble finding a solution on the web.
I'm sorry, but you will not be able to do this, as the smtp server requires some sort of authentication, from which to send from
I'd like to write a program, probably a servlet or something to run on the a google app engine that I can send an email to. So not a program to send email, but one that can receieve it and parse it.
My question is, what code or API are out there that can receive an email?
Basically on your google app engine you can use an inbound mail service.
Please see this documentation for more information.
http://code.google.com/appengine/docs/java/mail/overview.html#Receiving_Mail_in_Java
You cant send an email to a program, you send an email to a server, so what you are looking for is a way to access an email server via your program. Unfortunately there is no single solution here, you need to configure your program for every different email account/server you want to access. (If you have ever set up an account in outlook or something like it you will get the idea)
For example here is a link to the gmail api, you could use this to access gmail accounts
http://code.google.com/apis/gmail/
You need to have a mailbox to send message there and you could read messages with the code like this: http://www.java2s.com/Code/Java/Network-Protocol/GetEmailMessageExample.htm
This can be done with a built in Java library.
javax.mail
Check out this link. It should be able to help you get started.
This won't work for every mail server, but depending on your setup it might help.
To send an email to a Java program, that program must be running. Generally that means a server style (aka service) receiver is favored.
For the email to be received, the Java service must understand an email protocol. There are a number of protocols, but SMTP is the standard for receiving email. Once you have a service that understands SMTP protocol for receiving email, you have written a mail server.
Note that most people don't care to write a mail server, as a mail client needs to connect to the server and pull the email to make it readable. Keep this in mind when designing the solution to your problem.
I'm writing a program, that sends email messages and want to know when the receiver receives the email message I've sent to him. How can I do this using JavaMail API?
If I use SMTPMessage, how exactly to deal with the result after I've set the notify options?
SMTPMessage smtpMsg = new SMTPMessage(msg);
smtpMsg.setNotifyOptions(SMTPMessage.NOTIFY_SUCCESS);
There is no standard way of doing this that's accepted and honored across the board. I see that you have some options, though:
Add a header "Return-Receipt-To" with your e-mail address in the value. If the recipient of the e-mail has a client which honors this header, then a return receipt will be sent to you when the e-mail is opened. This is not reliable, mind you, as the user can always decide not to send the receipt, even if he has a client that supports it.
Add an image into your e-mail that loads from your server and put a parameter on the image that includes the user's e-mail address. When the e-mail loads, the image will load from your server. Write a script that collects the e-mail parameter and then delivers a blank image. This is also not reliable, however, as many mail clients prompt users if they wish to download images and they can always choose not to. Also, some (mostly older) e-mail clients do not support images.
Perhaps the most reliable way is not to include the message in your e-mail at all. Include only a link to a website where the message can be read, and include their e-mail address or a unique code in the link. This way, you know exactly who read the message. Of course, this has the downside that people aren't actually getting the message in their inbox, and they also may choose not to go to the website to read it.
Ultimately, I think you're going to have to come up with a creative solution to solve this problem, unless you're happy getting spotty results.
Ok, this is an old discussion, but:
I've found a simple and working solution here (link in spanish).
You just need to add one more field to the header of the message. To achieve this you must use method addHeader of Part class, implemented by Message class. This method receives 2 parameters, type and value of header.
To get confirmation you must add this header:
Disposition-Notification-To
And the value is the mail where we want to send the confirmation answer:
message.addHeader("Disposition-Notification-To","mail#example.com");
ATTENTION: be aware that, nowadays, a lot of mail servers like gmail are discarding this requests, so this will not have effect, but, if you are sure (like me) receiver server allows this, will work like a charm.
please see my answer here (when this questioned was asked about ruby on rails). Tis basically the same answer.
Email open notification - ruby on rails
There is another approach to finding out whether an email has been received or not, it's getting undelivered emails. I've seen a rather good Java implementation here.
They used javax.mail (for mail processing) and guava (for processing strings and collections).
Just add a dummy image with display set to none in your message.And set the src attribute of this image to the url you want to call
You can use SMTP message and request for a delivery status (I don't know if it's coming when the provider receive the mail or if it's when the user open the mail).
JavaMail don't support directly these feature directly and you have to read the RFC 3464.
I also find this thread with examples but didn't try it javamail
You can also look at websina