Pages: 1
RSS
How to check recipient domain to do something in macro
 
Hi there,

I have this macro, that checks with a New Mail, if it goes to a certain recipient. If so it adds my customer ID into the subject.

>>> %IF:"%TOADDR"="FirstName.LastName@domain.de":%SUBJECT="N123456 - "%-
It works like a charm, but I would like to just check for the DOMAIN, so that it does this with all recipients of that company. How do I do that?

I tried %IF:"%TOADDR"="@domain.de" but certainly it wasn't that easy ;-)

regards,
Jürgen
 
I cannot provide the answer, Jurgen, but regex may be your solution. I use regex is quite simple processes, but what you're seeking is the ability to have the data to left of @ ignored when comparing against the target domain. There is a TB!-oriented page on macros and regex at http://www.silverstones.com/thebat/tbfaq.html which may prove helpful. If you do figure it out, I would appreciate seeing your solution, as it would help others, I'm sure. Good luck.

david
 
Heya David,

luck was what I needed. I had tried unsuccessfully to get it working for maybe one hour, before posting my question. I tried again, and this time (after another hour) IT WORKS.

The trouble was not the regex search pattern. Not because I'm such a genius, but because I could google for it. The problem that took me so long was getting the macro to take the regex result of search in the email for the domain.

I did not understand how to do that, but by first trying the appealing versions and then the weird versions (from my inexperienced point of view) I stumbled over the right one that works. I always thought that the "%REGEXPMATCH=%TOADDR" bit would get the domain string and I would use the %REGEXPMATCH then again in the IF part, you know like a system variable. Like so:

%IF:"%REGEXPMATCH"="@example.com":
   ^^^^^^^^^^^^^^ thought this would BE the regex result, and IF it's the correct domain it would be like
                  "@example.com" = "@example.com" -> TRUE

Didn't work. Only when I used that full code piece in the IF part, it worked.

the working part results (I think) from the macro's POV in:

CODE:

%IF:"%REGEXPMATCH=%TOADDR"="@example.com":

BECOMES with the wanted domain:
%IF:"@example.com"="@example.com":   --> TRUE
OR
%IF:"@wrongdomain.fr"="@example.com":   --> FALSE

Learned something about TB macros, and I hope I will remember it at the next time I'll try do something nifty.


So this I just put at the beginning of the template, this is the regex part 1 - setting the pattern
Code
%SETPATTREGEXP="@(.*)$"%-
to see what regex actually finds (not needed after one knows that part works), it outputs what the regex sees as the domain part in the TO field:
Code
-->%REGEXPMATCH=%TOADDR<--

then here comes the thing that does the magic:

Code
%IF:"%REGEXPMATCH=%TOADDR"="@example.com":%SUBJECT="insertyourtext - %SUBJECT"%-
The %SUBJECT="insertyourtext - %SUBJECT"%- prevents the deletion of whatever text one was typing when going through the header fields in a new mail.

So one has to type into that macro the "example.com" domain and the text (like in my case my customer ID) at "insertyourtext".

all this I have put into my macro that gets started when I open a new message window.



sorry for the very long entry for a very short solution.




cheers,
Jürgen
 
Thanks a bunch for sharing such a detailed explanation. Many of us struggle with regex and your post will be undoubtedly helpful. I'm copying it for possible future use.

regards,
david
Pages: 1