언어 설정

Menu
Sites
Language
Sending Email using Messaging API

Hello, 

 

I'm having a problem sending an email which has a picture attachment.

Here is my code:

function mailInit() {

var serviceListCB = function (services) {

if (services.length > 0) {
mailService = services[0];
}
 
tizen.messaging.getMessageServices("messaging.email", serviceListCB);

}

function sendEmail(content, emailAddress) {

var msg = new tizen.Message("messaging.email");

msg.attachments = [ new tizen.MessageAttachment("/opt/usr/media/Images/Default.jpg", "image/jpeg")];

msg.body.plainBody = content;

msg.to = [emailAddress];
 
mailService.sendMessage(msg,
function() {
console.log("message sending successful.");
},
function(e) {
console.log("message sending failed.");
}
);

}

 

//caller

mailInit();

function sendMessage() {

sendEmail("This is a test message.""xxxx@gmail.com");

}

 

 

Problems:

First of all, I got an exception in this line:

 msg.attachments = [ new tizen.MessageAttachment("/opt/usr/media/Images/Default.jpg", "image/jpeg")];

 

 

Exception is

  1. eWebAPIError
    1. ABORT_ERR20
    2. AVPLAY_CURRUPTED_STREAM_ERR0
    3. AVPLAY_NETWORK_DISCONNECTED_ERR0
    4. AVPLAY_UNSUPPORTED_AUDIO_FORMAT_ERR0
    5. AVPLAY_UNSUPPORTED_VIDEO_FORMAT_ERR0
    6. AVPLAY_UNSUPPORTED_VIDEO_FRAMERATE_ERR0
    7. AVPLAY_UNSUPPORTED_VIDEO_RESOLUTION_ERR0
    8. DATA_CLONE_ERR25
    9. DOMSTRING_SIZE_ERR2
    10. FAIL_TO_PLAY_ERR0
    11. FAIL_TO_REQUEST_ERR0
    12. HIERARCHY_REQUEST_ERR3
    13. INDEX_SIZE_ERR1
    14. INUSE_ATTRIBUTE_ERR10
    15. INVALID_ACCESS_ERR15
    16. INVALID_CHARACTER_ERR5
    17. INVALID_DEVICE_ERR0
    18. INVALID_ITEM_ERR0
    19. INVALID_MODIFICATION_ERR13
    20. INVALID_NODE_TYPE_ERR24
    21. INVALID_RESPONSE_ERR0
    22. INVALID_STATE_ERR11
    23. INVALID_VALUES_ERR0
    24. IO_ERR0
    25. NAMESPACE_ERR14
    26. NETWORK_ERR19
    27. NOT_CONNECTED_SERVICE_ERR0
    28. NOT_FOUND_ERR8
    29. NOT_SUPPORTED_ERR9
    30. NOT_SUPPORTED_FUNCTION_ERR0
    31. NO_AVAILABLE_NETWORK_ERR0
    32. NO_DATA_ALLOWED_ERR6
    33. NO_MODIFICATION_ALLOWED_ERR7
    34. NO_PERMISSION_ERR0
    35. OUT_OF_MEMORY_ERR0
    36. QUOTA_EXCEEDED_ERR22
    37. SECURITY_ERR18
    38. SERVICE_NOT_AVAILABLE0
    39. SYNTAX_ERR12
    40. TIMEOUT_ERR23
    41. TYPE_MISMATCH_ERR17
    42. UNKNOWN_ERR0
    43. URL_MISMATCH_ERR21
    44. VALIDATION_ERR16
    45. WRONG_DOCUMENT_ERR4
    46. code8
    47. line63
    48. message"Not Found"
    49. name"NotFoundError"
    50. sourceURL"file:///opt/usr/apps/eSe2354BUd/res/wgt/js/app.mail.js"
    51. stack"[native code]↵App_sendsNote@file:///opt/usr/apps/eSe2354BUd/res/wgt/js/app.mail.js:63↵App_sendNote@file:///opt/usr/apps/eSe2354BUd/res/wgt/js/app.js:187↵NoteUi_handleSend@file:///opt/usr/apps/eSe2354BUd/res/wgt/js/app.ui.note.js:97↵NoteUi_handleSend@[native code]↵dispatch@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:3063↵triggerCustomEvent@file:///usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js:2334↵clickHandler@file:///usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js:2410↵dispatch@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:3063↵eventHandle@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:2681↵trigger@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:2946↵file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:3604↵each@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:611↵each@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:241↵trigger@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:3605↵triggerVirtualEvent@file:///usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js:1965↵handleTouchEnd@file:///usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js:2072↵dispatch@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:3063↵eventHandle@file:///usr/share/tizen-web-ui-fw/latest/js/jquery.js:2681↵[native code]"
    52. type"NotFoundError"
    53.  
    54.  

Secondly, I got an exception in
mailService.sendMessage and falls in the error callback function: error message is 

 

  1. eWebAPIError
  2.   ABORT_ERR20
  3. code0
  4. message"UnknownError"
  5. name"UnknownError"
  6. type"UnknownError"

Sorry for not organized posting but hope that helps to trace the issue.

Thanks

Christian.

 

 

Edited by: Brock Boland on 17 3월, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

9 댓글
Raghu Kona
Hi Christian, Have you configured email client on your device? Have you selected privileges in config.xml () WebAPIError, basically refers to errors due to not having proper privileges. However, I would recommend you to send a message without attachment first, later you can add an attachment. Here is the sample code for reference var msg = new tizen.Message("messaging.email", {plainBody: "I will arrive in 10 minutes.", to: ["raghu.kona@hotmail.com", "naga.kona@outlook.com"]}); console.log("msg = " + msg.body.plainBody); function messageSent(recipients) { for (var i = 0; i < recipients.length; i++) { console.log("The SMS has been sent to " + recipients[i]); } window.history.back(); return false; } if (msg == null) { return; } try { gEmailService.sendMessage(msg, messageSent, onError); } catch (exc) { alert("sendMessage exc:" + exc.message); } Regards, Raghu Kona
Christian Soe
Hello, Raghu. Your code is sending emails correctly. - Thanks for your nice code. But how can we add attachments to the email? Thanks. Christian.
Raghu Kona
Hi Christian, The code below allows you to add an attachment to the message. var msg = new tizen.Message("messaging.email", {plainBody: "I will arrive in 10 minutes.", to: ["raghu.kona@hotmail.com", "naga.kona@outlook.com"]}); msg.attachments = [new tizen.MessageAttachment("images/myimage.png", "image/png"), new tizen.MessageAttachment("docs/mydoc.pdf", "text/pdf")]; Regards, Raghu Kona
Christian Soe
Hi, Raghu, Perfect, it works now, I spent 10 minutes to notice I was using "Images/myimage.png" instead of "images/myimage.png". Another question: I wonder I need to create another topic or not. It's about using email compose dialog. I successfully launched email compose dialogue, referring this link: https://developer.tizen.org/forums/web-application-development/launch-tizen-email-composing-dialog But how do I open the compose dialogue already having an image attachment? I looked at the Email application's source code and saw it is accepting the "attachments" control data with full path to the attachment file. So I used this code create ApplicationControl var service = new tizen.ApplicationControl( 'http://tizen.org/appcontrol/operation/send', null, null, null, [ new tizen.ApplicationControlData('text', [content]), new tizen.ApplicationControlData('attachments', [attach])] //full path to the file ); But in the email compose dialog, I neither can even find attachment field nor add attachment manually. Thanks. Christian.
Raghu Kona
Hi Christian, Even I did n't find any luck in adding an attachment using email compose dialog. I have raised a Jira request, but have n't got any response. I decided to wait for the 2.1 SDK expected this week, with a fix for all these issues. https://bugs.tizen.org/jira/browse/TWEB-119 Regards, Raghu Kona
Josh Dobbs
I have spent a lot of time trying to get this to work before finally finding this thread. Is there a way to vote this bug up? https://bugs.tizen.org/jira/browse/TWEB-119
Christian Soe
Hello, Raghu, Tizen 2.1 SDK is finally released, but still can't find a way to launch Email Compose dialog with image attachment. Were you able to get this done? BTW, sending email using Messaging API was great in Tizen 2.1 so I can send emails which contain text and also the image attachment. Thanks. Christian.
Ashvini Kocharekar
Hi Raghu I tried replicating same in my app But it throws an error "sendMessage exc:gEmailService is not defined" Here is my code //Initialize function var init = function() { // caller debugger; sendEmail("This is a test message.", "ashvini.27.04@gmail.com"); }; $(document).ready(init); function sendEmail(content, emailAddress) { var msg = new tizen.Message("messaging.email", {plainBody: "I will arrive in 10 minutes.", to: ["abc@qpr.com", "ashvini@gmail.com"]}); console.log("msg = " + msg.body.plainBody); function messageSent(recipients) { for (var i = 0; i < recipients.length; i++) { console.log("The Email has been sent to " + recipients[i]); } window.history.back(); return false; } if (msg == null) { return; } try { EmailService.sendMessage(msg, messageSent, onError); } catch (exc) { alert("sendMessage exc:" + exc.message); } }
Raghu Kona
Hi, Your code is missing the initialization part. You have to initialize the email services before sending an email. Just call this method inside init function. var gEmailService; function mailInit() { var serviceListCB = function (services) { if (services.length > 0) { gEmailService= services[0]; } tizen.messaging.getMessageServices("messaging.email", serviceListCB); } Regards, Raghu Kona