| Welcome to the Zimbra :: Forums! | |
Welcome, if you would like to post a comment please register.
We also encourage you to explore all things Zimbra with our team and members of the community.
|  | 
10-23-2007, 11:57 AM
| | | [SOLVED] Can a zimlet send an email? Stoopid question perhaps: can a zimlet send an email "itself". That is - is there an API available to let a zimlet send an email as part of the various activities it's completing?
Apologies in advance if this is a lame question - had a look and couldn't find out.
Cheers,
Sean | 
10-24-2007, 10:33 AM
| | Project Contributor | |
Posts: 127
| | I edited the message to show full code
It_Seacom_Zimlet.prototype.getUserDisplayName =
function() {
if(!appCtxt.get(ZmSetting.DISPLAY_NAME)) return "";
return appCtxt.get(ZmSetting.DISPLAY_NAME);
};
It_Seacom_Zimlet.prototype.getUserReplyTo =
function() {
return appCtxt.get(ZmSetting.REPLY_TO_ADDRESS);
};
It_Seacom_Zimlet.prototype._sendMsg =
function(destName, destEmail, subject, body) {
var soapDoc = AjxSoapDoc.create("SendMsgRequest", "urn:zimbraMail", "noSave=0");
var m = soapDoc.set("m");
m.setAttribute("idnt", this.userID);
var node_e = soapDoc.set("e", null, m);
node_e.setAttribute("p", this.getUserDisplayName() );
node_e.setAttribute("a", this.getUserReplyTo());
node_e.setAttribute("t", "f");
node_e.setAttribute("p", destName);
node_e.setAttribute("a", destEmail);
node_e.setAttribute("t", "t");
var node_s = soapDoc.set("su",subject , m);
var node = soapDoc.set("mp", null, m);
node.setAttribute("ct", "text/plain");
var subnode = soapDoc.set("content", body, node);
var command = new ZmCsfeCommand();
var resp = command.invoke({soapDoc: soapDoc});
var r = "Message sent";
DBG.println(AjxDebug.DBG2, "result:" + r);
this.displayStatusMessage(r);
};
Last edited by lfasci; 02-28-2008 at 11:44 AM..
| 
10-24-2007, 10:48 AM
| | | Thanks! Thanks - a quick follow-on question: that is JavaScript creating a SOAP request - right? Where would I find the API documentation for those Zimbra SOAP APIs?
Cheers,
Sean | 
10-24-2007, 01:51 PM
| | Zimlet Guru & Moderator | |
Posts: 467
| | The code is really documented.... in the code. Thanks for digging this far, I wonder if one of you would be so kind as to put this up on the wiki? | 
10-25-2007, 07:55 AM
| | | Up on Wiki Happy to put it up on the Wiki. Will have a dig around and see where best to put that.
Cheers,
Sean | 
10-29-2007, 02:41 AM
| | Project Contributor | |
Posts: 127
| | SOAP docs | 
02-23-2009, 08:28 AM
| | | Hey there
In a few words: Lorenzo's perfect snippet lacks one feature though... Attachments! That's why I'm here now... :-(
In soap.txt: Code: <SendMsgRequest [suid="{send-uid}"] [needCalendarSentByFixup="0|1"] [noSave="0|1"]>
<m [origid="..." rt="r|w"] [idnt="{identity-id}"]>
<e t="{type}" a="{email-address}" p="{personal-name}" [add="1"]/>+
<su>{subject}</su>*
[<irt>{Message-ID header for message being replied to}</irt>]
<mp ct="{content-type}">
<content>...</content>
</mp>
<attach [aid="{attach-upload-id}"]>
[<m id="{message-id}"/>]*
[<mp mid="{message-id}" part="{part-id}"/>]*
[<cn id="{contact-id}"/>]*
</attach>
</m>
</SendMsgRequest> I found the part I needed, I then started investigating what gives me the IDs I need here...
Well, I'm pretty lost with "which does what, and where"...
Have you ever published some of your internal dev schematics for the overall architecture (UML or something like that)? That would be pure gold for me...
As far as I can see, I'm supposed to upload (how do I call the dialog?) a file (found various js files about the subject, but even there, kinda lost...) in zimbra on the dedicate fileuploadservlet. Then I should receive an attachment id (where?), and then I'll proceed in setting it inside the soapDoc.set("attach"...) call to attach whatever I want to the message.
Is anybody so kind to address me in the right direction? I like to get dirty and wet (ehm... nevermind!): once on the right route, I'd be independent in proceeding further on, but this time it's a ocean too huge for me (at least for the time slices I'm dedicating to the project, considering that this is NOT my default job area...) | 
04-20-2011, 07:36 AM
| | | Even if thread is marked SOLVED , I'm still little lost in understanding how the sending mail thorugh zimlet mechanism works ...
I'm trying to put place a button to reject a particular mail selected from the "mail pane" . Here's the code that  should  send a mail in response of rejection Code: com_example_rejectmsg_HandlerObject.prototype._rejectSelectedMail =
function(controller) {
var message = controller.getMsg();
appCtxt.getAppController().setStatusMsg("Rejected:"+ message.subject);
var rejection = new ZmMailMsg;
appCtxt.getAppController().setStatusMsg(rejection.toString());
try{
var toV = new AjxVector ;
var fromV = new AjxVector;
var fromAddr = new AjxEmailAddress("foo@example.com",AjxEmailAddress.FROM,"foo","foo",false);
fromV.add(fromAddr,0,true);
var toAddr = new AjxEmailAddress ("bar@example.com",AjxEmailAddress.TO,"bar","bar",false)
toV.add(toAddr,0,true);
}
catch(err)
{
alert(err.message)
alert(err.stack)
}
try{
rejection.setAddresses(ZmMailMsg.HDR_FROM,fromV);
rejection.setAddresses(ZmMailMsg.HDR_TO,toV);
rejection.setSubject("REJECTED - " + message.subject );
rejection.setTopPart("text/plain");
}
catch(err)
{
alert(err.message)
alert(err.stack)
}
finally{
rejection.send(false,function(){appCtxt.getAppController().setStatusMsg("message sent");},function(){appCtxt.getAppController().setStatusMsg("message not sent");},null);
}
}; Please do not consider the poor style in coding ( i.e. address hardcoded ) , it's my first javascript try and has the only purpose to understand of to send mail within a zimlet.
Regards | | Thread Tools | Search this Thread | | | | | Display Modes | Linear Mode | | Why Join? Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.  |