32 lines
895 B
Python
32 lines
895 B
Python
from django.core.mail.message import MIMEText
|
|
#from email.mime.application import MIMEApplication
|
|
from django.core.mail.message import MIMEMultipart
|
|
|
|
# boto3 email functionality
|
|
import boto3
|
|
AWS_REGION = "us-west-2"
|
|
CHARSET = "UTF-8"
|
|
client = boto3.client('ses',region_name=AWS_REGION)
|
|
|
|
def sendemail(fromaddress,recipients,subjecttext,bodytext,attachment=None):
|
|
msg = MIMEMultipart()
|
|
msg['Subject'] = subjecttext
|
|
msg['From'] = fromaddress
|
|
msg['To'] = recipients
|
|
part = MIMEText(bodytext)
|
|
msg.attach(part)
|
|
|
|
# if attachment:
|
|
# part = MIMEApplication(open(attachment,'rb').read())
|
|
# part.add_header('Content-Disposition', 'attachment',
|
|
# filename=attachment)
|
|
# msg.attach(part)
|
|
|
|
result = client.send_raw_email(
|
|
Source=msg['From'],
|
|
Destination=msg['To'],
|
|
RawMessage=msg
|
|
)
|
|
|
|
return result
|