Reputation: 11
I have a question with sending email from Blackberry java development.
My application sends mail correctly, but it defaults in FROM the previously configured mail on the BlackBerry device, I don't know how to replace the header FROM for another email diferent like the email configured in the Blackberry device, I put my code below:
try {
Address() ad = new Address ("[email protected]", "Maria Gomez");
} Catch (AddressException e) {
try {
Store store = Session.getDefaultInstance().getStore ();
Folder [] folders = store.list (Folder.SENT);
Sentfolder folder = folders [0];
msg = new Message (sentfolder);
try {
String [] v = splitString (toField.getText (), ',', false);
toList = new Address [v.length];
for (int i = 0; i <v.length i + +)
{
toList [i] = new Address (v [i], "");
}
} Catch (AddressException e) {System.out.println (e.toString ());}
msg.addRecipients (Message.RecipientType.TO, toList);
msg.setSubject (subjectField.getText ());
msg.setContent (msgField.getText ());
msg.setFrom (ad);
if (toField.getText().compareTo("") == 0 | | fromField.getText().compareTo("")==0)
{
Dialog.alert ("ERROR: \ n Lack mail recipient \ no sender");
}
else
{
Transport.send (msg);
Dialog.alert ("the mail was sent");
subjectField.setText ("");
msgField.setText ("");
}
} Catch (MessagingException e) {
System.out.println (e.getMessage ());
Dialog.alert ("No mail was sent");
}
I try to use msg.setFrom (ad), but dosen't work, then i try using msg.setHeader ("FROM", "[email protected]") an neither work.
Waiting for helps, Thanks.
Upvotes: 1
Views: 830
Reputation: 4670
hi try this it work fine,,
public void TextMailSend()
{
String htmlContent = " Name:"+Name+ "\n Common Name:"+cmn_nm +"\n Radious:"+radius+"\n Year:"+yr+"\n Latitude:"+lat +"\n Longitude :"+lng ;
Message msg = new Message();
try
{
final Address address = new Address("","");
Address[] addresses = {address};
msg.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, addresses);
msg.setContent(htmlContent);
msg.setSubject("Subject");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(msg));
//Dialog.inform("Mail send fully.");
}
catch (AddressException e)
{
e.printStackTrace();
System.out.println("AddressException -->"+e.getMessage());
}
catch (MessagingException e)
{
e.printStackTrace();
System.out.println("MessagingException -->"+e.getMessage());
}
}
Upvotes: 1