Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataSource <Mail> element: HTML mail possible?

    Hello,

    Is it possible (SGWT Power 3.0) to use this:
    Code:
    <mail> 
            <from>noreply@myemail.com</from>  
            <to>$session.getAttribute("email")</to>  
            <templateFile>some_html_email_template.txt</templateFile>  
            <subject>aSubject</subject>  
            <messageData>$session.getAttribute("mailData")</messageData> 
    </mail>
    on some operationbinding, and then use HTML in the message some_html_email_template.txt file?

    I would love to send HTML emails via this way. I tried it, but it seems to send it as plain text at the moment.




    Thanks

    #2
    If the top of your message template has "Content-Type: text/html" this should work. However note that it's typical for an HTML email to also have a plain text version via mime multipart-alternative encapsulation, but there's currently no way to do this.

    Comment


      #3
      Hm this doesn't seem to work, I have the following template, saved as .txt file (at least, when reading it in Apple Mail)

      Code:
      Content-Type: text/html
      
      Dear $firstname $!tussenvoegsel $surname,
      
      <b>test</b>
      It that how it should be? Is the multipart thing the problem here?

      So the alternative is to call some Emailing class from the DMI that triggers this email?
      Last edited by Sytematic; 10 Apr 2012, 23:15.

      Comment


        #4
        Are you guys planning on adding this HTML-mail feature?

        Comment


          #5
          Sorry, that Content-Type approach won't actually work - we will accept certain mail headers in the template file but not that particular one.

          We've now added settings on the <mail> element for 3.1d that will allow controlling Content-Type. For any earlier versions consider a mail interceptor like procmail.

          Comment


            #6
            Thanks. I will have a look soon.

            For now I just sent the email through my Java emailer class.

            For people Googling this, a somewhat related thread (note the 'somewhat') is found here: http://forums.smartclient.com/showth...4799#post84799

            Comment


              #7
              Hello,

              This looks interesting. What does the full data source for mail look like? And how does one access this?

              Evan

              Comment


                #8
                It's a bit different. You can put a <mail> tag on an operationbinding, and then the mail will be sent after the operationbinding is done.

                for instance, if you put it on an add operation, and someone adds a record to the datasource, a mail is sent.

                See also: http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/docs/serverds/Mail.html

                Also: see around page 68 of the quick start guide

                Comment


                  #9
                  Originally posted by Isomorphic View Post
                  Sorry, that Content-Type approach won't actually work - we will accept certain mail headers in the template file but not that particular one.

                  We've now added settings on the <mail> element for 3.1d that will allow controlling Content-Type. For any earlier versions consider a mail interceptor like procmail.
                  Wow! This is so cool! For my fellow novitiates, it goes like this:

                  Your client-side code:
                  Code:
                  package com.smartgwt.sample.client;
                  
                  import com.google.gwt.core.client.EntryPoint;
                  import com.smartgwt.client.data.DSRequest;
                  import com.smartgwt.client.data.DataSource;
                  import com.smartgwt.client.widgets.Button;
                  import com.smartgwt.client.widgets.Canvas;
                  import com.smartgwt.client.widgets.events.ClickEvent;
                  import com.smartgwt.client.widgets.events.ClickHandler;
                  
                  public class Demo_Email_HTMLformat implements EntryPoint {
                  
                    DataSource dual = DataSource.getDataSource("DUAL");
                  
                    public void onModuleLoad() {
                  
                      Canvas canvas = new Canvas();
                  
                      Button button = new Button("Send");
                  
                      button.addClickHandler(new ClickHandler() {
                  
                        @Override
                        public void onClick(ClickEvent event) {
                  
                          DSRequest requestProperties = new DSRequest();
                  	requestProperties.setOperationId("emailHTML");
                  
                  	dual.fetchData(null, null, requestProperties);
                  
                        }
                  
                      });
                  
                      canvas.addChild(button);
                  
                      canvas.draw();
                    }
                  
                  }
                  Your DataSource operationBinding:
                  Code:
                  <DataSource 
                    ID="DUAL" 
                    serverType="sql" 
                    dataSourceVersion="1" 
                    dbName="somedb" 
                    schema="SYS" 
                    tableName="DUAL">
                      
                    <fields>
                      <field name="DUMMY" type="text" length="1" primaryKey="true"/>
                      </fields>
                      
                    <operationBindings>
                   	
                      <operationBinding operationType="fetch" operationId="emailHTML">
                        <mail contentType="text/html">
                          <from>No-Reply@someco.com</from>
                      	<to>some.person@comeco.com</to>
                      	<subject>Test</subject>
                      	<messageTemplate>
                  	  <html>
                  	    <body>
                  	      <p>Hello HTML World!</p>
                  	      <a href="http://blog.smartclient.com/">Test Hyperlink</a>
                  	    </body>
                  	  </html>
                  	</messageTemplate>
                        </mail>
                      </operationBinding>
                    
                    </operationBindings>
                      
                  </DataSource>
                  The only downside is now I might have to learn some HTML, which I have long deferred by use of Smart GWT ;)

                  Above works w/ Smart GWT Power 3.1d 09/05/2012 build.

                  Comment

                  Working...
                  X