Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 81
Registered: ‎07-16-2008
My Device: Curve - 8320
My Carrier: AirTel

Sending a Message with From indicating a different email address

Hi Everyone,

 

I want to send an email from my device which is provissioned on an email address "sgn@xyz.com". But I want to send an email which on sending, its recipient should see that the email has came from "hello@world.com". I was tring the following code, but it doesn't work and the recipient sees that same email address using which the email was sent:

 

 

SGN @ XYZ.COM

 

        String to = "vipul@mydomain.com";
String subject = "Email from someone Else";
String body = "This email's From is different from the sender's actual email";
String senderEmail= "hello@world.com";

try
{
Store store = Session.waitForDefaultSession().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sent = folders[0];

Message message = new Message(sent);
Address fromAdd = new Address(senderEmail, senderEmail);
message.setFrom(fromAdd);
message.setHeader("REPLY_TO", senderEmail);
message.setHeader("FROM", senderEmail);

Address toAdd = new Address(to, to);
Address toAdds[] = new Address[1];
toAdds[0] = toAdd;

message.addRecipients(Message.RecipientType.TO, toAdds);
message.setSubject(subject);
message.setContent(body);

Transport.send(message);
}
catch (Throwable e)
{
Log.error("Could not create/send email message.", e);
}

 

 

But what happens is, upon receiving the email, vipul@mydomain.com observe that the email was sent by sgn@xyz.com and not from hello@world.com.

 

Any one knows, how to achieve this ?

 

Regards,

 

(*Vipul)() ;

 

*(Vipul)() ;
BlackBerry Development Advisor
Posts: 15,727
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Sending a Message with From indicating a different email address

The from address is populated based on the email account you are sending the message from (you can have multiple email accounts on a single BlackBerry smartphone).

 

If the from address you wish to use is for one of these accounts, you can make this change.

 

Instead of opening the default session you'd need to use the ServiceBook class to locate the service record for the email address you wish to use.  You can find an example of this here:

 

How To – Send a message from a non-default email address
Article Number: DB-00561

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 81
Registered: ‎07-16-2008
My Device: Curve - 8320
My Carrier: AirTel

Re: Sending a Message with "FROM" indicating a different email address

[ Edited ]

Thanks Mark,

 

I was trying to set the FROM field to an email address which is not setup on the device. Reading your response, it appears that this is not possible.

 

 

*(Vipul)() ;
Developer
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Sending a Message with "FROM" indicating a different email address

You could write your own SMTP delivery mechanism that mangles the headers as you wish. This is far more difficult to achieve, however, and has obviously no immediate integration with the Blackberry messaging system already existing on the device.