Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Creating a Form and sending a email

  1. #1
    Join Date
    Apr 2011
    Location
    Brazil/Sao Paulo
    Posts
    21
    Rep Power
    4

    Question Creating a Form and sending a email

    Hi guys,

    As the title says, I need to create a form to send a email using a zimlet, I tried to understand another zimlet, like the SocialZimlet, but the code is somehow hard to understand and I didn't find any example on how to use a Combo-box. With that form, I want to pre-formatted and send a email to our support staff. Simple like that. Can I have some insight on how to do that?

  2. #2
    Join Date
    Apr 2007
    Location
    Paris, France
    Posts
    367
    Rep Power
    8

    Default

    If you just want a mail pre-formatted, doesn't the template zimlet from zimbra do what you want?
    You would just need to set the template and give it to your users.
    If not, we will need some more informations on what you need.

  3. #3
    Join Date
    Apr 2011
    Location
    Brazil/Sao Paulo
    Posts
    21
    Rep Power
    4

    Question

    If you are talking about the mail template zimlet, no.

    What we need here is to create a form, just like this one:


    https://examples.wufoo.com/forms/s7p7p9/

    And mail this, transparently, just by hitting the submit button. Later we are going to implement a archive system, so each form with user information will be put on a external database, and we are going to create a second zimlet (for administration), with reports and other stuffs.

    For now, I need some insight on how to create this form and how to mail it.

  4. #4
    Join Date
    Apr 2007
    Location
    Paris, France
    Posts
    367
    Rep Power
    8

    Default

    I don't see what is the difficulty on the form creation.
    If you use an additional app, you can use as a base the example zimlet of the wiki : ZCS 6.0:Zimlet Developers Guide:Examples:Tab iFrame - Zimbra :: Wiki
    As you can see in it there is the function "app.setContent()" that allow you to write HTML code in the app.
    So you should just create your html form any way you want and add it to the app content with this function.

    To send it by mail, you can send a soap request "SendMsgRequest" to send the message.
    You can check the example zimlet for soap request here : ZCS 6.0:Zimlet Developers Guide:Examples:SOAP API Basics - Zimbra :: Wiki
    You can also check the soap doc in your zimbra server for more informations about "SendMsgRequest" in /opt/zimbra/docs/soap.txt

  5. #5
    Join Date
    Apr 2011
    Location
    Brazil/Sao Paulo
    Posts
    21
    Rep Power
    4

    Default

    Well, I was trying to find a way to do that inside zimbra, if possible. As you said, with a soap request I can solve this, but how the social zimlet form works? It has a form using the Dwt, but I couldn't understand it.

    Also, I'm already inside zimbra, so how can I send a mail directly using some Zimlet API?

  6. #6
    Join Date
    Apr 2011
    Location
    Brazil/Sao Paulo
    Posts
    21
    Rep Power
    4

    Default

    I was fixed with the idea to do something like Zimbra Social Zimlet, with all those Dwt, anyway, we must be grateful when someone give some effort to help and in my last post that wasn't clear.

    Thank you, tdesorbaix! As I said, I can solve with SOAP, but I was just curious about how Social Zimlet uses form.

    In the future, I hope to be useful to this community, I believe that Zimbra has a great potential!

  7. #7
    Join Date
    Apr 2007
    Location
    Paris, France
    Posts
    367
    Rep Power
    8

    Default

    You are welcome .
    The Social zimlet is probably not the best choice as an example for using dwt items.
    There is example of use for those items in the zimlet training.
    Since your status indicate that you are a trained alumni, you should have access to the training material.

  8. #8
    Join Date
    Apr 2011
    Location
    Brazil/Sao Paulo
    Posts
    21
    Rep Power
    4

    Question

    Yes, I'm using the training material to help on it, but still a got some problems trying to figure out a way to put my code to work.

    Right now I need some help with this code. I want to dynamically generate a message that catch the content from a text input field, once I clicked on the Send link. This worked on the "com_zimbra_example_linkcallbacks" zimlet, but I couldn't make it work on my code. However, it, its uses a ZmDialog to put the form code for linkcallbacks and I'm trying to do that on my application tab.

    Also, can someone give me an example on how to uses jquery with my zimlet? I included it on the xml file, but I don't know how to use it directly on my code. There's some trick do to that?

    Here the code:

    Code:
    uspRP.prototype._geraRelatorio =
    	function() {
    		
    		var msgRel = "";
    		
    		var resp_assunto = document.getElementById("assunto_rel");
    		
    		if (resp_assunto.innerHTML != "") {
    			msgRel = "Subject: " + resp_assunto.value;	
    		} else {
    			msgRel = "Empty";
    		}
    				
    		appCtxt.getAppController().setStatusMsg(msgRel);
    
    };
    
    uspRP.prototype.appActive =
    	function(appName, active) {
    		var app = appCtxt.getApp(this._uspRPAppName);
    		var toolbar = app.getToolbar(); // returns ZmToolBar
    		
    		
    		switch(appName) {
    		
    		case this._uspRPAppName: {
    			if (active) {
    				
    				toolbar.setContent("<b>Central de Suporte: </b>");
    				html = [];
    				var _i = html.length;
    				
    				html[_i++] = "  <label for='assunto'>Resumo (50 caracteres):&nbsp;</label>";
    				html[_i++] = "	<input id='assunto_rel' type='text' name='assunto_rel' maxlength='50' size='50' value='teste'/><br/>";
                    		html[_i++] = "  <div align='right'><a href='#' id='gera_rel'>Send</a>'</div>";		
    				html.join("");
    		
    				app.setContent(html);
    				
    				var relClick = document.getElementById("gera_rel");
    				relClick.onclick = AjxCallback.simpleClosure(this._geraRelatorio, this);
    				
    				
    			}
    		}
    		}	
    		
    	
    };

  9. #9
    Join Date
    Apr 2011
    Location
    Brazil/Sao Paulo
    Posts
    21
    Rep Power
    4

    Question

    Well, I decided to forget for now how to catch a field data value on Content Tab Area, using a Dialog works just fine, and I didn't changed the code, just where I put it on Zimbra interface.

    With the form problem somehow solved (not in the way I wanted), now I got stucked with the send mail soap. I followed this:

    http://www.zimbra.com/forums/zimlets...end-email.html

    and this (userID):

    http://www.zimbra.com/forums/zimlets...imlet-jsp.html

    Here my piece of code that handle mail.

    Code:
    uspSuporte.prototype._okBtnListener =
    	function() {
    		var destName = "Teste envio email";
    		var destEmail = document.getElementById("email");
    		var subject = document.getElementById("assunto");
    		var body = document.getElementById("descricao");
    		// var statusMsg = "Mensagem enviada com sucesso para o email " + destEmail.value;
    		// appCtxt.getAppController().setStatusMsg(statusMsg);
    	
    		this._dialog.popdown(); // hide the dialog
    
    		this._sendMsg(destName, destEmail.value, subject.value, body.value);	
    	};
    
    uspSuporte.prototype.getUserDisplayName =
    	function() {
    		if(!appCtxt.get(ZmSetting.DISPLAY_NAME)) return "";
    			return appCtxt.get(ZmSetting.DISPLAY_NAME);
    		};	
    
    uspSuporte.prototype.getUserReplyTo =
    	function() {
    		return appCtxt.get(ZmSetting.REPLY_TO_ADDRESS);
    	};
    
    uspSuporte.prototype._sendMsg = 
    	function(destName, destEmail, subject, body) {
    		
    		var userId = appCtxt.getActiveAccount().getEmail(); // from 
    		
    		var soapDoc = AjxSoapDoc.create("SendMsgRequest", "urn:zimbraMail");
    		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);
    I'm working on the code using Zimbra Desktop, on the debug the soap envelop shows that idnt userID is undefined. I tried to force it with my mail address, but didn't work at all. I don't know if I'm missing something so I can send my form by mail.

    Still, I don't understand why I can use document.getElementById("email").value on the Dialog Interface but not on the Content Tab. There's some restriction on Zimbra? I notice that when I used a form that i wrote using jsp (form.jsp with post method), I could redirect it to result.jsp but I couldn't get any data using getParameter (<%= request.getParameter("motivo")%>), just a null parameter. Somehow, from this I understand that using a Dialog I could use with iframe a java servlet to do the job, but not on Content Tab, at least not on Zimbra Desktop, I didn't tested it on our production server.

    Well for know, can someone help me with my send mail problem. With this my piece of code should work and I be very grateful.

  10. #10
    Join Date
    Apr 2011
    Location
    Brazil/Sao Paulo
    Posts
    21
    Rep Power
    4

    Question

    OK, I put a lot of effort trying to make this work, but I'm really stucked. =(

    To help people that have problems with this, lets break this on parts. My code has two parts

    1) A Form that for this test, just collect a email, subject and body;
    - I built a simple dialog;
    - Using a button listener, I call a mail handler;

    2) The Mail Handler
    - I create a SOAP Envelope using the AjxSoapDoc.create method.
    - I send this envelope using ZmCsfeCommand invoke;

    Mail Handler Code - XML Version
    Code:
    // Send email using SOAP
    uspSuporte.prototype._sendMsg = 
    	function(destName, destEmail, subject, body) {
    		
    		// Define the type of Soap Message - "urn:zimbraMail"
    	    var soapDoc = AjxSoapDoc.create("SendMsgRequest", "urn:zimbraMail");
    
    		// Define node m
    	    var node_m = soapDoc.set("m", null, null);
    	    //m.setAttribute("idnt", this.userID);
    	    //m.setAttribute("idnt", this.getUserId());
    		//m.setAttribute("suid",this.sendUID);
    
    
    		// Set the recipient (to)  
    	    var node_to = soapDoc.set("e", null, node_m);
    		node_to.setAttribute("add", "0");
    	    node_to.setAttribute("p", destName);
    	    node_to.setAttribute("a", destEmail);
    	    node_to.setAttribute("t", "t");
    	    
    	    // Set the sender (from)
    	    var node_from = soapDoc.set("e", null, node_m);
    		node_from.setAttribute("p","Suporte");
    		node_from.setAttribute("a","mail@mail.com"); // modified to put on forum	    
    		node_from.setAttribute("t","f");
    
    		// Set the subject
    	    var node_subj = soapDoc.set("su",subject , node_m);
    	    
    	    // Set the message party (body)
    	    var node_mp = soapDoc.set("mp", null, node_m);
    	    
    	    // Set content type
    	    node_mp.setAttribute("ct", "text/plain");
    	    
    	    var node_content = soapDoc.set("content", body, node_mp);
    	    var command = new ZmCsfeCommand();
    	    var resp = command.invoke({soapDoc: soapDoc, asyncMode: true});
    	    var r = "Message sent";
    	    //DBG.println(AjxDebug.DBG2, "result:" + r);
    		appCtxt.getAppController().setStatusMsg(r);
    		return;		
    };
    Mail Handler Code - JSON Version
    Code:
    // Send email using json - SOAP
    uspSuporte.prototype._sendMail =
    	function(destName, destEmail, subject, body) {
    		
    		var jsonObj = {SendMsgRequest:{_jsns:"urn:zimbraMail"}};
    		var request = jsonObj.SendMsgRequest;
    		var msgNode = request.m = {};
    		
    		var addrNodes = msgNode.e = [];
    		
    		var addrFrom = {t:"f", a:"mail@mail.com", p:"Relatorio"};
    		
    		addrNodes.push(addFrom);
    		
    		var addrTo = {t:"t", a:this.destEmail, p:this.destName};
    		
    		addrNodes.push(addrTo);
    		
    		var bodyNodes = request.mp = [];
    		
    		var contentBody = {content: { _content:this.body}, ct: "text/plain"};
    		
    		bodyNodes.push(contentBody);
    		
    		msgNode.su = {_content:this.subject};
    		
    		request.suid = this.sendUID;		
    		
    	    var command = new ZmCsfeCommand();
    	    var resp = command.invoke({jsonObj: jsonObj, asyncMode: true});
    	    var r = "Message sent";
    	    //DBG.println(AjxDebug.DBG2, "result:" + resp);
    		appCtxt.getAppController().setStatusMsg(r);
    		
    		
    	};

    Debug (HELIX) for this envelope

    Code:
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
    <context xmlns="urn:zimbra">
    <userAgent xmlns="" name="ZimbraWebClient - FF3.0 (Linux)" version="7.1.4 GA"/>
    <session xmlns="" id="136"/>
    <format xmlns="" type="js"/>
    <authToken/>
    </context>
    </soap:Header>
    <soap:Body>
    <SendMsgRequest xmlns="urn:zimbraMail">
    <m xmlns="">
    <e add="0" p="Relatorio" a="mailto@mail.com" t="t"/>
    <e p="Suporte" a="mailfrom@mail.com" t="f"/>
    <su>
    email de teste zimlet
    </su>
    <mp ct="text/plain">
    <content>
    teste
    </content>
    </mp>
    </m>
    </SendMsgRequest>
    </soap:Body>
    </soap:Envelope>
    I got no response on Debug using the Json version. Here a valid SOAP message (JSON format):

    Code:
    Body: {
      SendMsgRequest: {
        _jsns: "urn:zimbraMail",
        m: {
          e: [
            0: {
              a: "mailto@mail.com",
              add: "0",
              p: "someone name",
              t: "t"
             },
            1: {
              a: "mailfrom@mail.com",
              p: "suporte",
              t: "f"
             }
           ],
          idnt: "8459449904948594859485945894855845",
          mp: [
            0: {
              content: {
                _content: "de novo
    
    some text here
    
    "
               },
              ct: "text/plain"
             }
           ],
          su: {
            _content: "teste envio"
           }
         },
        suid: 45849849849498
       }
     },
    Header: {
      context: {
        _jsns: "urn:zimbra",
        account: {
          _content: "mailfrom@mail.com",
          by: "name"
         },
        authToken: [authToken],
        notify: {
          seq: 2
         },
        session: {
          _content: 133,
          id: 133
         },
        userAgent: {
          name: "ZimbraWebClient - FF3.0 (Linux)",
          version: "7.1.4 GA"
         }
       }
     }
    I changed the suid and idnt numbers, just in case. And the official format of SendMsgRequest:

    Code:
    <SendMsgRequest [suid="{send-uid}"] [needCalendarSentByFixup="0|1"] [noSave="0|1"]>
      <m [f="!|?"] [origid="..." rt="r|w"] [idnt="{identity-id}"] [did="{saved-draft-id}"]>
        <e t="{type}" a="{email-address}" p="{personal-name}" [add="1"]/>+
        <su>{subject}</su>*
        [<header name="{header-name}">{header-value}</header>]*
        [<irt>{Message-ID header for message being replied to}</irt>]
        <mp ct="{content-type}" [ci="{content-id}"]>
          <content>...</content>
        </mp>
        <attach [aid="{attach-upload-id}[,{attach-upload-id}]"]>
          [<m id="{message-id}" [optional="0|1"]/>]*
          [<mp mid="{message-id}" part="{part-id}" [optional="0|1"]/>]*
          [<cn id="{contact-id}" [optional="0|1"]/>]*
          [<doc (id="{document-id}" | path="{document-path}") [optional="0|1"]/>]*
        </attach>
      </m>
    </SendMsgRequest>
    As I said, I'm stucked and need some help. Can anyone what is wrong with my code and what I need to send a mail using a zimlet?

Similar Threads

  1. Replies: 11
    Last Post: 09-18-2010, 04:32 AM
  2. sending a welcome mail after creating new mailbox.
    By Caterpillar in forum Administrators
    Replies: 1
    Last Post: 07-19-2010, 04:17 AM
  3. Replies: 1
    Last Post: 07-16-2010, 03:51 AM
  4. Replies: 5
    Last Post: 08-14-2008, 03:15 PM
  5. email -->php form. is this possible?
    By c4l3b in forum Zimlets
    Replies: 3
    Last Post: 10-13-2006, 01:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •