My mail server has been receiving a lot of spam with malicious links and attachments lately which have "From" addresses that contain a valid address from my domain with an additional #someotherdomain.hn address appended.
For example:
John Smith has an e-mail address of JohnSmith#mydomain.com
I receive e-mail with a "from" address of JohnSmith#mydomain.com#someotherdomain.hn
I would like to know if it is possible to block e-mail if the "from" address contains more than one "#" symbol.
You tag as Regex so I assume you want a regex that matches addresses with 2 '#' symbols.
Here it is:
/#.*#/
This will match any address with 2 (or more) #-signs.
It simply starts with matching '#', followed by zero or more characters, and finally another '#'.
All you have to do is delete the mail, if there's a match.
Edit:
To only match when one mail address has two '#' signs, and not when there are two addresses (each with a single #), you can use this Regex (assuming addresses are separated by comma ','):
/#[^,]*#/
Again, if there's a match, delete it.
Related
I have a long-form field ("Paragraph" type) in a Google Form. Users are expected to fill in any number of email addresses - at least one email, could be as many as 20-50 email addresses for some users.
I want to make sure that:
Each line is likely to be a valid email (by checking for a "#" character and a "." character)
Each line contains ONLY ONE email (by checking for "#" characters not separated by line breaks)
I know I can use the following string to check for two valid email addresses separated by a line break:
[a-zA-Z0-9_\.\+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-\.]+\n+[a-zA-Z0-9_\.\+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-\.]
However, this limits the user to submitting two (no more, no less) email addresses.
Is there a way to check for 1 email address per line, and allow anything from 1 to multiple emil addresses?
You could write the pattern with anchors and repeating 1 or more newlines followed by the same pattern.
^[\w.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+(?:\n+[\w.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+)*$
See a regex101 demo
I'm trying to form a regex to find the "from" address for any forwarded emails. There may be multiple formats, so it needs to match this pattern [Ffrom:] [there may be more text here including spaces,",A-Z,a-z,<,[, and multiple words] and then an email address. Here's what I have so far:
(?<=)[\w-]*#[\w-]*[.\w]*
This finds any email addresses, but I need it to only find those following this pattern. "From:" ["Possible Sender Name Here"] example-email1#test2.co.uk The line will always start with "[Ff]rom:" and this will be implemented in Powershell if that matters.
Usually headers are in the format From: "Fooy McBar" <Fooy#bar.com> which can be matched with:
-replace 'From:.*<(.+)>','$1'
Really the easiest way to match an email address at the end of a line is to just match everything after the last whitespace though:
-replace '^.*\s(.+)$','$1'
will match Fooy#bar.com in both:
From: "Fooy McBar" Fooy#bar.com
and
From: Fooy#bar.com
I Want to implement multiple email validation with specific domain using regex separated by ;. Requirement is to allow only two email id separated by semicolon.
I tried regex
^([\w+-.%]+#domain+\.com[~]?){1,2}$
it works fine but it validates email followed by ; . It should work as below
1) abc#domain.com valid
2) abc#domain.com;abc1#domain.com valid
3) abc#domain.com; invalid
4) abc#domain.com;abc1#domain.com; invalid
How to do it using regex?
Try:
"^([\w+.%-]+?#domain\.com)(;([\w+.%-]+?#domain\.com))?$"
It consists of addres 1
([\w+.%-]+?#domain\.com)
and zero or one further addres
(;([\w+.%-]+?#domain\.com))?
"^...$" makes shure that there are no other characters around.
Group 1 and Group 3 will contain the addresses
Test here
I'm new to mailgun and I'm trying to create a filter for "Matching on variations of the recipient of the email". I want it to work just like gmail. Example:
jondoe#gmail.com, jon.doe#gmail.com and j.o.n.d.o.e#gmail.com are the same accounts. Basically I want to remove dots from addresses.
I also want to add option + at the end of address for forwarding purposes. Example: jonedoe+facebook#gmail.com.
This is a regex for adding + at the end but how do I remove the dots?
match_recipient("^chris\+(.*)#example.com$")
Actually I have this now:
(chris)(#example.com)|(^((.*\.)+.*)#example.com$)|(^(chris)\+(.*)#example.com$)
And this will match this variations:
chris#example.com
chris+#example.com
chris+d#example.com
chris+3#example.com
chris+d8#example.com
chri.s#example.com
c.hri.s#example.com
c.h.r.i.s+#example.com
c.h.r.i.s+2d#example.com
.chris#example.com
chris.#example.com
And won't match these (as it shouldn't):
ch5ris#example.com
cchris#example.com
chriu#example.com
chriOs#example.com
chbis#example.com
cchhrriiss#example.com
michael#example.com
The only issue now is that it matches names with dots at the beginning and at the end. How do I fix this now?
I need to validate a string for valid email addresses or specific tokens (later to be replaced by email addresses) or a mix of both delimited by semi-colon. I need a little help with this regex I nearly got working.
It matches the tokens but not the email address at the start or end.
^(((<#a#>)+|[;])*|(([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*|((<#a#>)+|[;])*)$
Here is the answer posted by AlexBay which is working with my test data.
^((<#a#>)+|[;]|(([a-zA-Z0-9_\-\.]+)#([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)+$