Configuration - HomeMadePy/messages GitHub Wiki
In order to make creating messages easier, messages uses the jsonconfig package to store default profile settings and credentials. A config.json file is created in the following OS-specific filepath:
Mac OS X:
~/Library/Application Support/messages
Mac OS X (POSIX):
~/.messages
Unix:
~/.config/messages
Unix (POSIX):
~/.messages
Win 7+ (roaming):
C:\Users\<user>\AppData\Roaming\messages
Win 7+ (not roaming):
C:\Users\<user>\AppData\Local\messages
A typical config.json file may look like:
{
"MyProfileName": {
"email": {
"server": "smtp.gmail.com",
"from_": "[email protected]",
"port": 465
},
"twilio": {
"acct_sid": "AC1547383934732678...",
"from_": "+16195553232"
},
"slackwebhook": {
"url": "https://hooks.slack.com/services/ajklN/123hdhfjd5895",
"from_": "Your Robot"
}
}
}
In the above example, the message keyword profile should be set to the desired profile name. Multiple profiles can be saved, using only the profile specified by keyword argument. Note passwords and other secure credentials are not saved in the config file but instead are securely stored in your system's keyring.
The configuration feature can be invoked either through a python script/REPL session or via the CLI.
Note the use of the profile and save keyword argument.
>>> from messages import Email
>>> e = Email(from_='[email protected]',
to='[email protected]',
auth='p@ssw0rd',
profile='MyProfileName',
save=True)
>>> # at this point the config file is created and saved
>>> # in the filepath specified above
>>> e.send()
Now that your parameters and credentials have been saved, future invocations are easier!
>>> from messages import Email
>>> e = Email(to='[email protected]', profile='MyProfileName')
>>> e.send()
To create a config.json entry via the CLI, use the configure command.
First time use:
$ messages configure email
Configure a profile for: email
You will need the following information:
* From email address (e.g. [email protected])
* Email server url (e.g. smtp.here.com)
* Email server port number (e.g. 465)
Authorization/credentials required:
* Email service password
Continue [Y/N]? Y
Profile Name: myProfileName
From email address (e.g. [email protected]): [email protected]
Email server url (e.g. smtp.here.com): smtp.here.com
Email server port number (e.g. 465): 465
password: *********
[+] Configuration entry for <myProfileName> created.
[+] Configuration file location: /home/yourprofile/.config/messages/config.json
$
Later uses:
$ messages email myProfileName "Hello, this is a message" -t '[email protected]'