How to implement an email system

The way to fix this is to ‘align’ what the implementation refers to and the application model contains.

So you can rename ‘Mails’ to any collection you have in your application model that contains mails to send and remove some/all of the references to Admin, as 'CC': collection = empty is also valid

So as I currently have a communications tab in my application I just need to rename the mailer using the stuff from the communications collection?

I am not sure what you meant there. Can you share a part of your application model you would like to connect to?

Yes of course



i want to connect to the communication part in the second image. Anything i need to rename there or in the implementation

It would probably need to be something like this:


I see the logic and as i added it everything went smoothly but yet now ‘Admin’ isnt found in ‘attributes’ also ‘Users can create mail directly?’ has the same issue. Is it maybe because in my code ‘Admin’ is a type of User

No, it’s simply that you didn’t add an Admin section to your model (yet). It is basically the same as using a function that you didn’t declare yet or using a variable that is not defined.

There are two solutions: don’t refer to Admin any more (so remove the references) or add an Admin group and properties in that group that are referred to. Same for the other error(s)

But why would i add an Admin section to my code if it already exists?(Its a state of a stategroup ‘Type’ of ‘Users’)

Ah! The location of something in the model and consequently, the path towards it, matters. See how .‘Admin’ is referenced here after root:

Now see the part in this application model where the ‘Admin’ group is placed directly under the root:
image

So all the property and state names that you use are not mixed together in some kind of global name pool: everything is named within its context.

so, i should make an ‘Admin’: group but what should it contain except the ‘User Management’ group. Also ive made a ‘Users can create mails directly?’ stategroup which fixed one of the errors

Yes, or remove the references, you can also make the CC like this:

'CC': collection = empty

okay, ive made the collections empty but what about the stategroups, also there is a group which has ‘From Address’ which gives off an error too(state constraint violation for ‘has reference’. Unexpected state for ‘has reference’:
implementation.alan(4, 31): - expected: ‘yes’
application.alan(125, 23): - but found: ‘no’
application.alan(125, 23): defined by .‘Mails’.‘From Address’ of type ‘application’!‘node’.‘attributes’.‘type’?‘property’.‘type’?‘text’). Also ive made the Admin group but im wondering what to put in it

The path that is used there contains a >‘From Address’, which is the syntax for following a reference. A reference looks like this, for instance:

‘From Address’: text -> ^ . 'Admin' . 'Addresses'[]

By the way, have you gone through the full tutorial (A, B and C) on the platform website? If not, I urge you to do that, because it will guide you through some of these basics.

https://alan-platform.com/docs/

yeah, ive done it but some of the things still confuse me particularly the stuff im trying to do now

Have you looked at this part, for instance?

https://alan-platform.com/pages/tutorials/model/2024.2/application-tutorial.html#references

Next to that: we try to make the error messages as informative as possible, but sometimes they require a bit of yoda-logic: you have to turn the message around to understand what it means.

In this case not, actually. The message is quite clear in that sense. It says that in .‘Mails’.‘From Address’ of type text in the implementation.alan is expected to have a reference (because of the >‘From Address’, which can only be done with a reference), but in the application model it is not found to have a reference.

Unexpected state for ‘has reference’:
implementation.alan(4, 31): - expected: ‘yes’
application.alan(125, 23): - but found: ‘no’
application.alan(125, 23): defined by .‘Mails’.‘From Address’ of type ‘application’!‘node’.‘attributes’.‘type’?‘property’.‘type’?‘text’

I know im trying to take the lazy route now but could you please see my implementation and application and just tell me how and what to fix because ive been working on that for like 3 days and my brain is short-circuiting. i learn better that way and im only a student. Sorry for asking again. Application:






Implementation:



Sorry for asking that much but at this point ive lost all hope and i just want to get this over with

Ok, replace the current pieces for ‘From’, ‘Redirect all mail’, ‘CC’ and ‘BCC’ in your implementation.alan with the implementation that follows and see what happens:

‘From’: group = (
‘Name’: text = $^ $‘mail’.‘Sender’
‘Address’: text = $^ $‘mail’.‘From Address’
)

‘Redirect all mail’: stategroup = ‘No’ ( )

‘CC’: collection = empty
‘BCC’: collection = empty

now everything works but upon building it says that in deployment.alan ‘mailer’ is missing in ‘systems’