This repository was archived by the owner on Jul 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
feat: added implementation to send mail using python #31
Open
anushkrishnav
wants to merge
4
commits into
appwrite:master
Choose a base branch
from
anushkrishnav:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 📧 Sending Welcome Emails using Mailgun's Email API | ||
A sample Python Cloud Function for sending a welcome email to a newly registered user. | ||
|
||
## 📝 Environment Variables | ||
Go to Settings tab of your Cloud Function. Add the following environment variables. | ||
|
||
* **MAILGUN_API_KEY** - API Key for Mailgun | ||
* **MAILGUN_DOMAIN** - Domain Name from Mailgun | ||
|
||
## 🚀 Building and Packaging | ||
|
||
To package this example as a cloud function, follow these steps. | ||
|
||
```bash | ||
$ cd demos-for-functions/python/welcome-email | ||
|
||
$ virtualenv env | ||
|
||
$ source env/bin/activate | ||
|
||
$ pip3 install requirements.txt | ||
``` | ||
Create a .env file with the following content | ||
|
||
``` | ||
MAILGUN_API_KEY = 'Replace this with your key here' | ||
MAILGUN_DOMAIN = 'Replace this with your Domain' | ||
|
||
``` | ||
|
||
* Ensure that your folder structure looks like this | ||
``` | ||
. | ||
├── main.py | ||
├── env | ||
└── requirements.txt | ||
``` | ||
|
||
* Navigate to the Overview Tab of your Cloud Function > Deploy Tag | ||
* Input the command that will run your function (in this case "python3 main.py") as your entrypoint command | ||
* Click 'Activate' | ||
|
||
## 🎯 Trigger | ||
|
||
Head over to your function in the Appwrite console and under the Settings Tab, enable the `users.create` and `account.create` event. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import requests | ||
import os | ||
import json | ||
|
||
payload = json.parse(os.environ.get('APPWRITE_FUNCTION_EVENT_PAYLOAD')) | ||
name = payload['name'] | ||
email = payload['email'] | ||
|
||
|
||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We wont be needing this once we upload the cloud function. |
||
|
||
basedir = os.path.abspath(os.path.dirname(__file__)) | ||
key = os.environ.get('MAILGUN_API_KEY') | ||
domain = os.environ.get('MAILGUN_DOMAIN') | ||
|
||
request_url = 'https://api.mailgun.net/v2/{0}/messages'.format(Domain) | ||
request = requests.post(request_url, auth=('api', key), data={ | ||
'from': 'Welcome to My Awesome App <[email protected]>', | ||
'to': email, | ||
'subject': 'Welcome on board {0}!'.format(name), | ||
'text': 'Hi {0}\nGreat to have you with us. ! 😍'.format(name) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests==2.25.1 | ||
urllib3==1.26.2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refer to the readme here
https://github.com/appwrite/demos-for-functions/tree/master/python/object-detection
We need the dependencies to be installed in the .appwrite folder
Secondly it's missing the instructions to create a tarfile