How to implement an email system

As my project is growing im wondering how can i send emails to users and also how to implement emails in the registration. heres my code:

users
dynamic: .‘Users’
user-initializer: (
‘Type’ = create ‘Normal’ ( )
)
passwords: .‘Passwords’
password-value: .‘Data’.‘Password’
password-status: .‘Data’.‘Active’ (
| active => ‘Yes’ ( )
| reset => ‘No’ ( )
)
password-initializer: (
‘Data’ = ( )
)
authorities: .‘Authorities’
identities: .‘Identities’>‘User’
identity-initializer: ( )

interfaces

root {
can-update: user .‘Type’?‘Admin’

'Users': collection ['Name'] {
	'Name': text
	'Type': stategroup (
		'Admin' { }
		'Normal' { }
	)
}
'Passwords': collection ['User'] {
	'User': text -> ^ .'Users'[]
	'Data': group {
		can-update: user is ( ^ >'User' )

		'Password': text
		'Active': stategroup (
			'No' { }
			'Yes' { }
		)
	}
}
'Authorities': collection ['Authority'] {
	'Authority': text
	'Identities': collection ['Identity'] {
		'Identity': text
		'User': text -> ^ ^ .'Users'[]
	}
}
'Communication': collection ['Messages'] {
	'Messages': text
	'Subject': text
	'User': text -> ^ .'Users'[]
}

}

numerical-types

Hi there,

I sent you a couple of files a few days ago, do you still have them? Those are most of what you need, expect the part in the application model. The easiest solution is to copy paste the interface in the application model and create a one-on-one implementation to connect it to the interface.

Regards, Rick

Indeed, I still have them, but I am kind of confused on how to put them in the project. Like paste/write the code in the application.alan or are other folders and files required to be created

Ok, here is an example of a project that has the files I sent you within the normal folder structure. If you add it to the wiring.alan as in the example, building the project will create the right folders as well.

Thanks for the help. Small suggestion: similarly to the user registration guide in the documentation maybe make a guide for a mailer service implementation since it would be more accessible to newer users etc.

Hi! Yes, you’re right, it would be helpful of course. We are currently very occupied with building all kinds of systems on the platform ourselves and improving the platform at breakneck speed at the same time. When that settles down a bit, we expect to have more time available for the production of more elaborate examples, documentation, tutorials, etc. Regards, Rick

Just one last question while implementing the files etc everything went smoothly but there is just one error. It says that ‘connector’ is not found in system-types.

Can you show the contents of your versions.json file? It should contain an entry for the connector with its current latest version:

"connector": {
	"version": "36.7"
}

If you have edited that file, you should run ‘Alan Fetch’ again and after that, the error about the missing system-type should disappear.

it was missing from there when i imported it everything worked again but hell broke loose in the systems/server/interfaces/providing/mailer/implementation.alan giving errors for things not existing meanwhile they do any way to fix that. Also for example it says that ‘Admin’ does not exist clearly defined in the application.alan

Hi, you will need to add a part to your application model and adapt the implementation.alan accordingly. The implementation.alan follows the structure of the interface and expects you to provide data for each property in it. A collection can be initialized with = empty, all other properties will have to be bound to something in the application model.

Until that is done, it will show errors.

A small tip: you probably only need one branch, so this should be enough:
image

If there is another branch next to ‘Mail’ = … , you can remove that one.

could you explain more on the adding to the implementation.alan part, sorry im just really confused if possible maybe even help with the aforementioned task, since this is probably the last problem i need to fix before i can actually attach a proper service like mailgun etc

It is basically mapping: with a set of transformations you are expected to map a part of the application model to the interface to implement. The basic possibilities you have are visible in the example I sent you. You can also dive into the reference manual here:

https://alan-platform.com/pages/docs/datastore/116/provided_interface_implementation/grammar.html

thanks again, will try to do that

I’ve just realised this but in the implementation.alan there are ‘mailings’ etc that I don’t actually have in the application.alan should I implement them in there. Also Ive re-read the documentation page but still things don’t get clearer. Sorry if I’m being obnoxious but could you maybe like give me a step-by-step tutorial to potentially clear up inconsistencies. Thanks in advance.

Hi there!

Its understandable that you have questions. We don’t have the time to create a tutorial for this at the moment, so questions it is then.

The ‘Mailings’ part can be removed, it is just a separate, second branch of entries in the ‘Items’ collection.

Kind regards, Rick

wont removing it give off more errors and also eliminate some of the actual goals of the system, still thanks for the replies

No, you should read this implementation.alan at a high level like this:

Items in the mailer interface will be filled with:

  • Mails, coming from the ‘Mails’ collection that are in the right state (‘Sending’)
  • Mailings, coming from the ‘Mailing’ . ‘Recipients’ subcollection that are in the right state

When removing the ‘Mailings’ part/branch, that part of the mapping is removed and will not generate errors any more (that would have been errors coming from properties not found in the application model).

So i should remove only the Mailings part. Okay, did that now only ‘Admin’ and ‘Mails’ give off the error.I just realised i could upload images. I hope that makes the explaining part easier

Those are the only errors left

The errors will say (you can hover above them to see the details): The ‘Mails’ collection cannot be found and the ‘Admin’ group cannot be found. It can see ‘Mails’ should be a collection because of the * behind it.

Yes! That’s exactly what the errors say, so do I just need to move the asterisk behind the ‘Mails’? Also what about the ‘Admin’