Importing mail from Gmail to discord

Hello to you dear community of n8n,

First of all I’m new and I want to say thank you for the system that you offer :slight_smile:

Here is my problem:

I want to import under certain conditions a message on discord when an email is received, I use the imap protocol for as a trigger and a switch to split the results and send them by discord.
The problem is that the end of the subject of the email changes depending on the order number:

(New order #X)

Uploading: image.png…

So I’m trying to put an undefined value behind it so that it goes to the right branch :slight_smile:

Thanks for your help

HI @HantZ

Not 100% sure what the problem is as there is no image or workflow included in your post.
But If you have this subject and want to extract the order number You can simply user a replace in an expression. so something like {{$json[“subject”].replace(“New order “,””}} to remove the prefix from the subject.
If this is not what you are looking for, please give us a bit more information on what you want to do. For example, giving an input and expected output would be very helpful.

2 Likes

Hi, thanks a lot for your quick answer

Here is my workflow:

I hope I’ve pasted it right ^^

Ok, so now we have a workflow. But I still do not know what you are trying to do. :slight_smile:

Please explain the problem, so we can try to help. :slight_smile:

Yes, I’m sorry but if I don’t explain it, it won’t work ^^

So when a mail is received in my mailbox it points to a switch, I would like this switch to choose the right branch, the 1 on the subject “Nouvelle commande n°”

Knowing that there is a number after “n°” and that it is different for each order.
This number prevents it from sorting and goes to branch 0 and therefore in error, I am looking for a solution that could either stop the search for the switch after “n°” or delete the number

(I admit that I am new and so I did not know where to put your request “{{$json[“subject”].replace(“New order “,””}}”

Thank you for your help :slight_smile:

Thanks, that makes it a lot easier. :slight_smile:
You only need to add the set node Can also do it in the switch node, but the setnode might be easier to understand.
With this example you would add a field where the number is removed and then use that field in your switch. With this you can easily add more things in that set node if needed.

1 Like

So I’m probably doing something wrong ^^’
I added like you in the set and in the switch but the value is not deleted and still goes in the error

Am I doing something wrong? I think that placing the “replace”

Thank you again for taking the time for my problem which looks basic ^^’

Sorry @HantZ

I read it all completely wrong. You can easily just use the Switch node with the Contains option.

quick example:

1 Like

@HantZ Did you get all this working? I would love to do the same thing.

No problem @BramKnuever :wink: ,
This is exactly what I was looking for ! Thank you so much for your help with my problem! It helped me a lot !

Thank you :slight_smile:

1 Like

You can follow @BramKnuever 's advice :wink: