PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio â†’ WINDEV 2024 â†’ DYNAMIC FIELDS IN AN EMAIL
DYNAMIC FIELDS IN AN EMAIL
Iniciado por guest, 06,jun. 2015 11:39 - 17 respuestas
Publicado el 06,junio 2015 - 11:39
Hi,

In the past I have seen in an example the functionality to add fields to a text field like this:

[ firstname] I cannot find the example. Does anyone have a quick answer to this

regards
Allard
Publicado el 06,junio 2015 - 17:01
Hi Allard,

I'm not sure what you are asking here...

Maybe you're looking for the "replace" function? or stringbuild?

Best regards
Publicado el 07,junio 2015 - 19:16
Hi,

I have to give it a try . If no one knows it . I know there is an example that does it.

Something like this

if hreadseekfirst ( file , fileid id ) then

file.name = "[Name]"
etc
end

Then when creating the email in a text field say something like this:

Hello mister [Name] you have won a price

when the mail is sent it takes the tekst in the email and replaces [name] with file.name


regards
allard

ps
A cool way to let the user of the app make emails to sent to selected customers
Publicado el 07,junio 2015 - 20:00
Hi Allard,

try

[%MyFile.Name%]

or %[MyFile.Name]%

I've seen this use somewhere in the report editor.
Publicado el 07,junio 2015 - 21:09
Hi,

I`ve done this with a small parseclass.

1. You let the user build a email template using "tokens" for example database fields. and build tokens from for example the customer table.
//Example of build tokens s is string = HListItem(Kunde) ss is string FOR EACH STRING sAstr OF s SEPARATED BY CR // ss = "["+sastr+"]" ss = sAstr TableAddLine(TABLE_token2,ss) END
2. Then before you send each mail you parse in the field value this can be as advanced you want:
//Adds tokens to internal array //To call for a customer table,Call is AddTokens(Customer..name) PROCEDURE AddTokensFromFile(iFileName) s is string = HListItem({iFileName},hLstDetail) tn is string tv is string n is int FOR EACH STRING sArec OF s SEPARATED BY CR tn = ExtractString(sArec,1,TAB,FromBeginning) IF tn <> "" THEN n = Seek(:Tokens,asLinear,"TokenName",tn,1) IF n = -1 THEN n = Add(:Tokens) Tokens[n].TokenName = tn Tokens[n].FTokenName = "["+tn+"]" Tokens[n].Type = ExtractString(sArec,2,TAB) Tokens[n].HFType = ExtractString(sArec,3,TAB) Tokens[n].Size = ExtractString(sArec,4,TAB) Tokens[n].nSubScripts=ExtractString(sArec,5,TAB) Tokens[n].sCaption = ExtractString(sArec,6,TAB) tv = iFileName+"."+tn Tokens[n].TokenValue = "" END END END // Set the record value when record is retrived.. //Perhaps a when exception end could do here to // Call is: // Hreadfirst(Vustomer) //Class:SetToken(Customer) PROCEDURE SetTokenValueRecord(ifilename) s is string = HListItem({ifilename}) n is int tv is string FOR EACH STRING sTn OF s SEPARATED BY CRLF n = Seek(:Tokens,asLinear,"TokenName",sTn,1) IF n >= 1 THEN tv = ifilename+"."+sTn :Tokens[n].TokenValue = {tv} END END //The actuall parse PROCEDURE Parse(iStr) sPstring is string = iStr nFound is int = 0 s is ANSI string d is Date t is Time st is DateTime LOOP nFound = 0 FOR EACH ds OF :Tokens // MyTrace(">>Type: "+ds.Type+" - "+ds.tokenname,ds.HFType) IF Position(sPstring,ds.FTokenName,1) >= 1 THEN SWITCH ds.HFType CASE 1,2 sPstring = Replace(sPstring,ds.FTokenName,ds.TokenValue) nFound = 1 CASE 11 t = ds.TokenValue sPstring = Replace(sPstring,ds.FTokenName,TimeToString(t,maskSystemTime)) CASE 24 st = ds.TokenValue d = st..Date t = st..Time sPstring = Replace(sPstring,ds.FTokenName,DateToString(d,maskSystemDate)+" "+TimeToString(t,maskSystemTime)) nFound = 1 CASE "N" sPstring = Replace(sPstring,ds.FTokenName,ds.TokenValue) nFound = 1 OTHER CASE MyTrace("Type",ds.Type,ds.HFType,ds.TokenName,"Unknown") END END END IF nFound = 0 THEN BREAK END END RESULT sPstring
3. If you build this into a class the call would be:
PD is object ParseString_Class dynamic = new ParseString_Class PD.AddTokensFromFile(Customer..Name) PD.SetTokenValueRecord(Customer) sMailContent is string = PD.Parse(fLoadText(gsEtiFolder+"\EPOSTmal.txt")) // EPOSTmal.tx<== is a email text template.
Cheers
Tor-Bjarne
Publicado el 07,junio 2015 - 22:45
Hi Allard

as I was saying, just use the replace function to replace the [name] tag by it's value in your loop on your recipient

Best regards
Publicado el 08,junio 2015 - 00:33
Hi

Yep . I found it

thanks

Allard
Publicado el 08,junio 2015 - 10:38
That's what I do; as Fabrice says, I insert a place holder (variable) in the text of the email and then use the "Replace" function.
Publicado el 08,junio 2015 - 11:48
Hi Allard,

Sorry about my bloated answer, if it was just the replace/stringbuild command you where looking for. :)

Cheers
Tor-Bjarne
Publicado el 08,junio 2015 - 23:48
Hi , indeed,

Coding is not so difficelt.

However I have an odd problem. It works with little mails. Bigger mails are not sent. I saw in the documnetation that email.html can handle 4 gb. That is enormous.

My php settings are limited to 10 mb per mail. So that is ok as well.


Ok if I try to sent this mail it isnot sent:

Hallo [voornaam] [achternaam],

U heeft uw gegevens opgeslagen op [datum] om [tijd] en daarbij aangegeven dat u deze gegevens ook via de mail wilt ontvangen, Hierbij uw gegevens zoals ze zijn geregistreerd:

[bedrijfsnaam]
[gebruikersnaam]
[voornaam]
[achternaam]
[wachtwoord]
[adres]
[postcode]
[woonplaats]
[tel]
[mobiel]
[emailadres]


then when I remove some fileds and it looks like this it is sent:

Hallo [voornaam] [achternaam],

U heeft uw gegevens opgeslagen op [datum] om [tijd] en daarbij aangegeven dat u deze gegevens ook via de mail wilt ontvangen, Hierbij uw gegevens zoals ze zijn geregistreerd:

[bedrijfsnaam]
[gebruikersnaam]
[voornaam]
[achternaam]
[wachtwoord]
[adres]
[postcode]

in my sql the property is tekslong . If I take a look at it it has quite some makup in it . But it is save good. I have a preview option and when I run that in a web page the preview of the email looks just fine.

So the problem is in the sending of the email . any one an Idea How to fix this?

regards
Allard
Publicado el 09,junio 2015 - 00:26
Hmm

The problem lies in the fact that it has , somehow , no valid html. and the spamfilter of the hosting company does not allow it to be sent

Hmm odd huh

regards

allard
Publicado el 09,junio 2015 - 00:30
I do this quite extensively in my application using the REPLACE. Users can build their own library of HTML email templates using a set of predefined tags and then I have a procedure that manages the whole thing that I call when the user selects a template. Works really nicely.

I recommend using double brackets in HTML. [[TagName]]
Publicado el 09,junio 2015 - 10:14
Hi, yes it is great.

I made it so that users can drag the [ stuff] into a html edt control. But the spam filter is the problem.

Ok so I shoudl change for instance [name] to [[name]] ? I Will give it a try

Thanks
Allard
Publicado el 09,junio 2015 - 11:40
Hi,

tried that but no succes

I sent the hosting company an email. Itis clearly a spamfilter problem


regards
Allard
Publicado el 10,junio 2015 - 14:39
Hi Allard,

The problem is the content of the email sent. Check it out. If you send an email with no HTML formatting, simply use the Text property to send plain text instead of incorrectly formatted HTML. Otherwise, create an HTML template, put your [tags] in it, the when you Replace() make sure to convert the TextToHTML().

Make sure the content does not look like spam. Again, the problem is not on code side (as far as code is concerned) but the actual content of the email seen as spam. Just make sure the content you send does not look like spam to the spam algorithm on the email server.

Best regards,
Alexandre Leclerc
Publicado el 10,junio 2015 - 22:24
Hi Alexandre

Well they worked on it but it doesnot work yet. Indeed it is the html sent is pcsoft makeup with a lot of tags in it.

ButI cannot change the html edtit box, I after I repalce the [stuff] I put the string in the
email.html . And I cannot change anything on that as well.

So I should do something like this?

newstring is string
newstring = texttohtml(variabele after replece)

email.html = newstring

thanks
Allard
Publicado el 10,junio 2015 - 22:44
Hi Allard,

Yes, this is the principle. Here is an example:

Email.HTML = ReplaceAllTagsToValue(sHTMLTemplate) PROCEDURE ReplaceAllTagsToValue(sHTMLTemplate is string) : string s is string = sHTMLTemplate s = Replace(s,"[tag1]",TextToHTML("Value1")) s = Replace(s,"[tag2]",TextToHTML("Value2")) //... RESULT s
Best regards,
Alexandre Leclerc
Publicado el 11,junio 2015 - 11:32
Hi . Iam sorry but I think i donnot get it completely I did following

when sending the mail:
IF EmailTeksten.Gebruiktekst = 1 THEN
sBericht is string = EmailTeksten.emailtekst
stringmail is string
sHtmlstring is string
stringmail = email_gebruikers_variabele_items(

sBericht,gnMemberID)

sHtmlstring = TextToHTML(stringmail)
Trace( sHtmlstring)
Trace( "_____________")
Trace( stringmail)
Email.HTML = sHtmlstring

//The procedure with the replace to get the [stuff]

PROCEDURE email_gebruikers_variabele_items(sMessageType, sgebruikerID)
sDatumgoed is string
sDatumgoed = DateToString(DateSys(),"DD-MM-YYYY")

IF HReadSeekFirst(gebruikers,gebruikersID,sgebruikerID) THEN
sContent is string = sMessageType
sContent = Replace(sContent, "[bedrijfsnaam]",gebruikers.Bedrijfsnaam )
sContent = Replace(sContent, "[gebruikersnaam]]",gebruikers.gebruikersnaam)
sContent = Replace(sContent,"[voornaam]",gebruikers.VoorNaam)
sContent = Replace(sContent,"[achternaam]",gebruikers.Achternaam)
sContent = Replace(sContent,"[wachtwoord]",gebruikers.wachtwoord)
sContent = Replace(sContent,"[adres]",gebruikers.Adres)
sContent = Replace(sContent,"[postcode]",gebruikers.Postcode)
sContent = Replace(sContent,"[woonplaats]",gebruikers.Woonplaats)
sContent = Replace(sContent,"[huisnummer]",gebruikers.huisnummer)
sContent = Replace(sContent,"[tel]",gebruikers.Tel)
sContent = Replace(sContent,"[mobiel]",gebruikers.Mobtel)
sContent = Replace(sContent,"[emailadres]",gebruikers.Emailadres)
sContent = Replace(sContent,"[datum]",sDatumgoed)
sContent = Replace(sContent,"[tijd]",TimeToString(Now(), " : HH h MM "))
RESULT sContent
END

this gets a whole lot of more html like code that is not accepted by the spamfilter.


regards

Allard