Jump to content

Sending Email Dynamically in XSLT


sgasch

This topic is 6334 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I know that this topic has been covered already in some aspects, but reading through the answers and looking at the test files, I'm not sure that my exact question has been answered.

I have a website in which a user creates/updates a comment and then submits it. Under Filemaker Pro 6 Unlimited, a script is run which checks to see whether or not an email must be sent. If the answer is yes, then a Send Mail step is executed in FMP.

In XSLT, it looks like I would want to have the Send Mail template always called (as the action from the submission of the comment), but only have the Send Mail portion done if a test shows it is needed. Does this make sense???

Also, I currently have a cc email address in the FMP SendMail step, but don't see anything in the fmxslt:send _email parameters that supports that. Is there a set of parameters other than the one shown in the FMSA Custom Web Publishing Guide that handles a cc address?

Link to comment
Share on other sites

Correction to the previous post (I must have reset the FM Client and FM Server and changed the posting, but not realized it). I am using FMP Developer 7 on OS X Tiger and FMP Server 7 Server Advanced, but will be using FMP Server 8 Advanced when finished.

Link to comment
Share on other sites

You need to place the call for fmxslt:send_email into :)

...

...

Since returns either True or False depending on whether the email was sent successfully, you might want not to output it, but to place into another condition:

...

Email sent.

...

To specify cc and other parts of email header you need to combine all of them into a string:

[email protected]?subject=...&from=...&cc=...

and pass the string as the first parameter to fmxslt:send_email.

Link to comment
Share on other sites

All of the values that would be input to the send_email function are Filemaker Pro fields. I assume that I would define variables in XSLT set equal to the fieldnames and then use the variables in the function. Is that correct?

Also, I have looked at some of the documentation, but am still unclear on what external setup is needed to communicate with an SMTP server. I have 2 Mac Servers (running OS X, but not server and 2 Windows Servers). None of them are really SMTP Servers. In FMP 6, I was able to set up the Mail Client and use an account that I have on an SMTP Server. Would the same thing work here? Does FMP 8 use the Mail Clilent on OS X, for example?

Link to comment
Share on other sites

The SMTP server can be specified in the FMSA Web Publishing console, http://yourhost/fmi/config , in the XSLT Publishing setup.

For generation of the e-mail URL string, you can use concat() to glue together the string parts. Either XPath expressions for the fields or variables can be used. You can concatenate up to 8 strings, if you need more, you have to do that in steps (e.g. store the concatenated string in a variable and use the variable a further concat()).

Link to comment
Share on other sites

Not quite, if I understand you correctly. You'll have to get the field contents first. In XSLT this is

fmrs::field[@name=...]

And there may be something before the fmrs::field depending on how you evaluate this. You also need to concatenate the individual values together to get the whole string. That is you can do it in FileMaker itself

Address & "?subject=" & Subject & "&from" & ...

and then get this calculated field, or you can get the different fields separately and concatenate them in the xslt stylesheet:

concat( fmrs::field[@name='Address'], '?subject=', fmrs::field[@name='Subject'], ... )

Then you can pass the string to the function as the first argument.

To set up the server to send email you need to get to it via the control panel

http://the-server-ip-or-name/fmi/config

and then in the XSLT section specify the mail account. The server can use any SMTP account, e.g. your own account from your provider: just supply the user name and password.

Link to comment
Share on other sites

I think I have some of it, but somehow the connections are missing to me. I have the following questions:

1. From Address - currently in FMP 6 Unlimited, the from address comes from the Mail application (OS X) and is the name of the server (i.e., not an email address). I can make it the email address of the main user - will that work if it is mailing something from the Server?

2. I have created a URL containing the concatenated fields for the first argument. An example would be:

[email protected]?subject=CCR 446G-Draft0071 submitted to CMO for review & amp;[email protected]&[email protected];;[email protected]&

Is this right???

3. A new record is created in a form (in new.xsl) and then an email needs to be generated indicating the status (which depends on what is input on the form) and the info about the record. Can the sendmail be put into this form or should it be on the reply page? (i.e., what type of action is needed to get the sendmail to be executed?)

I feel like I am so close - please help me fill in the blanks.

Link to comment
Share on other sites

1. I probably don't quite understand you. The ‘from’ address cannot be just the name of the server. It must be something like [email protected]. But if you're talking about what to enter in the FMSA web control panel, then you don't need the address. What you need is your SMTP server address, account and password. It must be something like 'smtp.domain.com', 'johndoe' and '123'. Or whatever : This is what you enter once in Mail Preferences - Accounts and then forget about it.

When you send the email, you pass the "from" address via the string we're talking about. It's just the same citizen as other addresses and the subject line.

2. The URL looks correct, but you might want to start with a simpler string that has only from, to and perhaps subject. For testing try to make the subject a single word without spaces.

Also, just in case, you won't use this string as URL, you just pass it to the fmxslt:send-email function.

3. The latter, i.e. the reply page. The process is that: user gets to the new page, fills in the form and presses the submit button. The result is sent to FMSA, FMSA executes the command (i.e. '-new'), returns the result and transforms it with the reply page xsl file, e.g. reply.xsl. The result of '-new' is a found set of just one record that has been just created.

This is where you send the email. E.g. if you check that some field is not empty:


  

    

      
Email is sent.

    

    

      
Email is not sent.

    

  

To play safe you should check for error first, but this is another story.

Link to comment
Share on other sites

I tried the sendmail and got an error message indicating a problem with SMTP Field (which is the one that I had in the previous post). I tried doing simpler things, but still got the same error.

With respect to the email addresses, they are all of the same format. It's just that the from address is just an email address, with no relationship to the server itself. I'm using an SMTP server which is used to send mail, so that should be OK.

Any ideas on where to look for this nebulous SMTP field error???

Link to comment
Share on other sites

This is the code:

E-mail has been sent.

E-mail error.

I am now getting the message "Email sent", but nothing gets to me (the toemaill is one of my email addresses and the from is the other one).

The form is filled out in a new page, but doesn't include the email addresses or anything there - just some fields to help populate the body of the message. The code shown above is in the new_reply page.

Link to comment
Share on other sites

PARTLY WORKING!!!

I was wrong with the last post - I just didn't wait long enough for the email. However, the variable that I used for the body doesn't come out, except that the body of the message didn't come out.

When I added something in quotes before the variable containing the body, as in:

, the phrase New CCR has been added came out, but the body was still missing. I tried both putting quotes around the string in emailCMObody and leaving them out, but neither worked.

What am I missing?

Link to comment
Share on other sites

Another try:

When I put in the following:

instead of

I get a 10202 or SMTP field error. The field defined for URLforemail is :

'?subject= New CCR&[email protected]'

By the way, I'm not sure when I need quotes and when I don't need them.

If someone can tell me how to attach a file to this, I will attach the whole xsl file (which might help), but I don't know how to do that.

Link to comment
Share on other sites

Glad you have it working : Since $emailCMObody gets its value from a field, then the most likely cause is that the field is not on the layout. If not, try to output the variable on the page to see what it contains:


There's no need to enclose the contents of your "body" field in quotes, but they won't harm either; they will be a part of the email message.

I'm not sure about why the second URL doesn't work though. It looks pretty valid. The only thing I'm not sure about is the space after '?subject='. Could you please remove it and try again?

I know that to attach a file you need press the "Full Reply" button below the reply field and find the "Manage files" link there, then upload the file, and then I don't know : Maybe it will just remain attached. Alternatively you can upload the file to something like mytempdir.com

Link to comment
Share on other sites

The value of the field is correct, but somehow it doesn't work when I put it in the call. I think I finally have figured out how to attach the .xsl file, so if you take a look at that, you might notice something else.

By the way, there was never a blank between the s and the gasch in the real file, only one in the replies.

Thanks so much.

new_reply.zip

Link to comment
Share on other sites

Finally got this working:

Many thanks for all your help.

Do you know of anyplace where this is written up (besides the CWP Guide from FMP, which is not sufficient, in my humble opinion)?

Maybe those who used to use the script step in FMP all turned to PHP. I considered that, but didn't want to translate all of the pages for my 18 Websites, so I stuck with XSLT.

Link to comment
Share on other sites

While you think you weren't of much help, the hints here and there, along with some trial and error, helped me to get to the correct format of the send_email. This was the last piece of the puzzle that needed to be solved when I began this massive translation from FMP 6 and CDML to FMP 8 and XSLT.

In fact, most of the issues that I had (like dealing with headers and footers properly - i.e., not just putting them inline with the rest) have been solved by reaching out to folks on forums and mailing lists.

Thanks again.

Link to comment
Share on other sites

This topic is 6334 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.