i have several .pst files and need all the mail-addresses, i sent mails to. The example code of the library allows me to traverse every mail in the file, but i can't find the right getter to extract the mail address of the receiver.
To traverse every mail, i use the code from this site:
https://code.google.com/p/java-libpst/
PSTMessage email = (PSTMessage) folder.getNextChild();
while (email != null) {
printDepth();
System.out.println("Email: " + email.getSubject());
printDepth();
System.out.println("Adress: " + email.getDisplayTo());
email = (PSTMessage) folder.getNextChild();
}
The getDisplayTo() method only displays the receivers names but not their mail addresses.
What getter do i need to use to get the addresses?
Best,
Michael
First method : : available getters
getSenderEmailAddress
getNumberOfRecipients
getRecipient(int)
Second Method : parse the header and collect the email address (a_sHeader is a string)
Session s = Session.getDefaultInstance(new Properties());
InputStream is = new ByteArrayInputStream(a_sHeader.getBytes());
try {
m_message = new MimeMessage(s, is);
m_message.getAllHeaderLines();
for (Enumeration<Header> e = m_message.getAllHeaders(); e.hasMoreElements();) {
Header h = e.nextElement();
// Recipients
if (h.getName().equalsIgnoreCase(getHeaderName(RecipientType.REC_TYPE_TO))) {
m_RecipientsTo = processAddresses(h.getValue());
}
...
}
} catch (MessagingException e1) {
...
}
Related
I'm trying to send email with inline attachment using MS Graph. I know how to send email without attachment but when I'm trying to send message with attachment I don't know how can I add this attachment to the message.
Here is my code:
// recipients
Recipient recipient = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "tom#mail.com";
recipient.emailAddress = emailAddress;
List<Recipient> recipients = List.of(recipient);
// body
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "<html><body>my image:<br><img src='cid:my_image_CID'></body></html>";
// inline image
Attachment attachment = new Attachment();
attachment.isInline = true;
attachment.contentType = ".png";
attachment.id = "my_image_CID";
//attachment.contentBytes - I DON'T SEE THIS FIELD...
// message
Message message = new Message();
message.subject = "my subject";
message.body = body;
message.toRecipients = recipients;
//message.attachments = ??? - how to create this object?
there are examples in the internet that I can set attachment.contentBytes but I don't see this attribute.
For the message I can set attachments object which is of type
AttachmentCollectionPage
but I don't know how can I create this object.
I'm using the following versions:
Microsoft Graph Java SDK » 5.42.0
Microsoft Graph Java Core SDK » 2.0.14
You need to use FileAttachment which extends Attachment and has property contentBytes.
I am integrating Plivo SMS API with my java web application. I want to send messages through my application. I am referring to https://www.plivo.com/docs/getting-started/send-a-single-sms/ link.
Below is the code snippet:
String authId = "{my Auth_id}"; //Your Authentication ID
String authToken = "{my auth Token}"; //Your authentication code
RestAPI api = new RestAPI(authId, authToken, "v1");
LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>();
parameters.put("src", "+44*******"); // Sender's phone number with country code
parameters.put("dst", "+91*******"); // Receiver's phone number with country code
parameters.put("text", "Hi, text from Plivo"); // Your SMS text message
try {
// Send the message
MessageResponse msgResponse = api.sendMessage(parameters);
// Print the response
System.out.println(msgResponse);
// Print the Api ID
System.out.println("Api ID : " + msgResponse.apiId);
// Print the Response Message
System.out.println("Message : " + msgResponse.message);
if (msgResponse.serverCode == 202) {
// Print the Message UUID
System.out.println("Message UUID : " + msgResponse.messageUuids.get(0).toString());
} else {
System.out.println(msgResponse.error);
}
} catch (PlivoException e) {
System.out.println(e.getLocalizedMessage());
}
I tried to run this code using console application as well as web application.I am getting exception "com.plivo.helper.exception.PlivoException: Connection to https://api.plivo.com refused". What is wrong with my code? Am I missing anything here?
Plivo Sales Engineer here.
Please check your firewall settings to ensure that it's not blocking any traffic. Also, are you using a web proxy? If yes, make sure that your application is using this proxy to handle connections.
I am trying to create an HL7 message in Java and then print the resulting message. I am faking basic patient information and then adding the Drug Prescription information. Then, I want to print the complete message but I wasn't able to use the API correctly. I am new at using HL7, so I know I'm probably missing some required segments and even using the wrong ones, can you please help? This is my current code:
public RXO runDrugPrescriptionEvent(CMSGeneric cmsgen) {
CMSDrugPrescriptionEvent cmsic = (CMSDrugPrescriptionEvent) cmsgen;
ADT_A28 adt23 = new ADT_A28();
try {
adt23.initQuickstart("ADT", "A08", cmsic.getPDE_EVENT_ID());
// We set the sex identity (male or female)
if (cmsic.getBENE_SEX_IDENT_CD() == 1) {
adt23.getPID().getSex().setValue("Male");
}
else {
adt23.getPID().getSex().setValue("Female");
}
// We set a fake name and family name
adt23.getPID().insertPatientName(0).getGivenName().setValue("CMS Name " + MainTest.NEXT_PATIENT_ID);
adt23.getPID().insertPatientName(0).getFamilyName().setValue("CMS Family name " + MainTest.NEXT_PATIENT_ID);
MainTest.NEXT_PATIENT_ID++;
RXO rxo = new RXO(adt23, new DefaultModelClassFactory());
rxo.getRxo1_RequestedGiveCode().getCe1_Identifier().setValue("" + cmsic.getPDE_DRUG_CD());
rxo.getRxo18_RequestedGiveStrength().setValue("" + cmsic.getPDE_DRUG_STR_CD());
rxo.getRxo19_RequestedGiveStrengthUnits().getCe1_Identifier().setValue("" + cmsic.getPDE_DRUG_STR_UNITS());
rxo.getRxo5_RequestedDosageForm().getCe1_Identifier().setValue("" + cmsic.getPDE_DRUG_DOSE_CD());
rxo.getRxo11_RequestedDispenseAmount().setValue("" + cmsic.getPDE_DRUG_QTY_DIS());
HapiContext context = new DefaultHapiContext();
Parser parser = context.getPipeParser();
String encodedMessage = adt23.getParser().encode(rxo.getMessage());
logger.debug("Printing Message:");
logger.debug(encodedMessage);
return rxo;
} catch (IOException e) {
System.out.println("IOException creating HL7 message. " + e.getMessage());
e.printStackTrace();
} catch (HL7Exception e) {
System.out.println("HL7Exception creating HL7 message. " + e.getMessage());
e.printStackTrace();
}
return null;
}
With this code, the logger prints the following message:
MSH|^~\&|||||20160331101349.8+0100||ADT^A08|110001|PDE-00001E6FADAD3F57|2.3
PID|||||CMS Family name 100~^CMS Name 100|||Female
But I was expecting to see the RXO segment as well. How can I achieve that?
I found that changing the message type from ADT_A28 to ORP_O10 would let me have all the fields I need, as ADT_A28 wasn't the appropriate message for the kind of information I needed. There's a complete example on how to set a great amount of segments in this type of message here. Then, I was able to print the complete message using the PipeParser:
HapiContext context = new DefaultHapiContext();
Parser parser = context.getPipeParser();
String encodedMessage = parser.encode(msg);
logger.debug("Printing EREncoded Message:");
logger.debug(encodedMessage);
I try to access email account on a certain email server via "imap" through java mail. I did some research on this. And I find the following code which works for gmail.
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
public class DeleteMessageExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String username = args[1];
String password = args[2];
// Get session
Session session = Session.getInstance(
System.getProperties(), null);
// Get the store
Store store = session.getStore("imaps");
store.connect(host, username, password);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));
// Get directory
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++) {
System.out.println(i + ": " + message[i].getFrom()[0]
+ "\t" + message[i].getSubject());
System.out.println("Do you want to delete message? [YES to delete]");
String line = reader.readLine();
// Mark as deleted if appropriate
if ("YES".equals(line)) {
message[i].setFlag(Flags.Flag.DELETED, true);
}
}
// Close connection
folder.close(true);
store.close();
}
}
However, I need to specify the args[0] to be imap.gmail.com args[1] to be usrname, args[2] to be password. And if I replace imap.gmail.com by the ip address 74.125.224.86, it no longer work.
My question is suppose I have an account on yahoo mail, what the hostname I should use?
I tried imap.yahoo.com, mail.yahoo.com and the ip address.
If you know the answer, would you mind also told me what is the regular rule to find out what kind hostname I should use?
Thanks a lot.
Unlike Gmail, Yahoo Mail's IMAP services is not a totally standard IMAP service. You need send some special tokens before you login. You need to modify the JavaMail API in order to connect to Yahoo Mail through IMAP. The latest JavaMail 1.4.4-SNAPSHOT release supports Yahoo Mail as well. You can get it here
The code below uses javamail API to access gmail,
String host = "pop.gmail.com";
int port = 995;
Properties properties = new Properties();
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
final javax.mail.Session session = javax.mail.Session.getInstance(properties);
store = session.getStore("pop3s");
store.connect(host, port, mCredentialaNme, mCredentialApss);
// ***************************************************************
Folder personalFolders[] = store.getDefaultFolder().list( "*" );
// ***************************************************************
for (Folder object : personalFolders) {
// ***********************************
System.out.println( object.list("*") );
// ***********************************
if ((object.getType() & javax.mail.Folder.HOLDS_MESSAGES) != 0){
object.open(Folder.READ_ONLY);
Message messes[] = object.getMessages();
System.out.println(object.getFullName());
System.out.println("====================");
for (Message object1 : messes) {
System.out.println(object1.getFrom() + " - " + object1.getSubject());
}
object.close(false);
}
}
if (store.isConnected()) {
store.close();
}
The trouble is that this code only lists the INBOX folder whereas there are no less than 20 labels defined.
What should be done to get the code to list/access these nested folders/labels?
Don't use POP, use IMAP if you want labels/folders.
As noted in the javamail docs, due to the nature of the POP protocol, a POP message store always
Contains only one folder, "INBOX".