mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Add a example script to distributes the contacts you receive sequentially to emails in a list.
This commit is contained in:
parent
e9406f42ff
commit
e8eac7fa54
41
Contact-Distribution/README.md
Normal file
41
Contact-Distribution/README.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
# Contact 'Leads' Distribution
|
||||
Distributes the contacts you receive sequentially to emails in a list.
|
||||
|
||||
Use case
|
||||
--------
|
||||
When you have a sales team and would like the contacts received on a form
|
||||
to be equally distributed between them.
|
||||
|
||||
How to Use in cPanel
|
||||
--------------------
|
||||
|
||||
1. Create an email account that will receive the contacts ```Ex: sellers@domain.com```
|
||||
2. Create the email accounts where the contacts will be distributed.
|
||||
3. Upload the script to the server. (note: DO NOT use a public folder)
|
||||
4. Change script privileges `$chmod 744 contact-distribution.py`
|
||||
5. Change the list of sellers (the same as you created in step 2)
|
||||
|
||||
```python
|
||||
# list with sellers or emails for distribution
|
||||
sellers = [('Seller 01', 'seller01@domain.com'),
|
||||
('Seller 02', 'seller02@domain.com'),
|
||||
('Seller 03', 'seller03@domain.com')]
|
||||
```
|
||||
|
||||
6. Change the primary receiving email. (the same one you created in step 1)
|
||||
|
||||
```python
|
||||
s.sendmail("sellers@domain.com", sellers[nextSeller][1],
|
||||
msg.as_string())
|
||||
```
|
||||
|
||||
7. Add a new forwarding to the mail distribution.
|
||||
|
||||
![Imagem do cPanel](docs/images/cpanel_encaminhadores01.jpg)
|
||||
|
||||
8. Forward it to the script.
|
||||
|
||||
![Imagem do cPanel](docs/images/cpanel_encaminhadores02.jpg)
|
||||
|
||||
|
||||
Done.
|
52
Contact-Distribution/contact-distribution.py
Normal file
52
Contact-Distribution/contact-distribution.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/python
|
||||
# coding: utf-8
|
||||
|
||||
import email
|
||||
import smtplib
|
||||
import sys
|
||||
import csv
|
||||
|
||||
# Capture stdin message via pipe
|
||||
msg = email.message_from_file(sys.stdin)
|
||||
|
||||
# list with sellers or emails for distribution
|
||||
sellers = [('Seller 01', 'seller01@domain.com'),
|
||||
('Seller 02', 'seller02@domain.com')]
|
||||
|
||||
# Check the size of the vendor list
|
||||
totalSellers = len(sellers)
|
||||
|
||||
# Get the last seller that received email
|
||||
lastSeller = open('lastseller.txt', 'r').read() # use the full path of file
|
||||
|
||||
# Determines the next seller who will receive email
|
||||
if int(lastSeller) == totalSellers - 1: # If the last one you received is the last
|
||||
nextSeller = 0 # on the list, get the first one on the list.
|
||||
else: # If not,
|
||||
nextSeller = int(lastSeller) + 1 # get the next one.
|
||||
|
||||
currentSeller = str(nextSeller)
|
||||
|
||||
# records which seller is receiving the current email.
|
||||
fvend = open('lastseller.txt', 'w') # use the full path of file
|
||||
fvend.write(currentSeller)
|
||||
fvend.close()
|
||||
|
||||
# Check if you have an email for reply
|
||||
if not msg['reply-to']:
|
||||
emailContact = msg['from']
|
||||
else:
|
||||
emailContact = msg['reply-to']
|
||||
|
||||
# writes log to csv
|
||||
with open('emails.csv', 'a') as fcsv: # use the full path of file
|
||||
mailwriter = csv.writer(fcsv, delimiter=';')
|
||||
mailwriter.writerow(
|
||||
[msg['date'], msg['subject'], emailContact,
|
||||
sellers[nextSeller][0]])
|
||||
|
||||
# Forward the email to the seller of the time.
|
||||
s = smtplib.SMTP('localhost')
|
||||
s.sendmail("sellers@domain.com", sellers[nextSeller][1],
|
||||
msg.as_string())
|
||||
s.quit()
|
BIN
Contact-Distribution/docs/images/cpanel_encaminhadores01.jpg
Normal file
BIN
Contact-Distribution/docs/images/cpanel_encaminhadores01.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
Contact-Distribution/docs/images/cpanel_encaminhadores02.jpg
Normal file
BIN
Contact-Distribution/docs/images/cpanel_encaminhadores02.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
1
Contact-Distribution/lastseller.txt
Normal file
1
Contact-Distribution/lastseller.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
Loading…
Reference in New Issue
Block a user