Skip to content

Commit

Permalink
Merge pull request #24 from diggyk/master
Browse files Browse the repository at this point in the history
Email fixes
  • Loading branch information
gmjosack committed Jul 10, 2015
2 parents 216bf6d + a1dcc4d commit dfdad2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
22 changes: 22 additions & 0 deletions hermes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,28 @@ def create(
quest.description
)
)

msg = "QUEST {} STARTED:\n\n\t\"{}\"\n\n".format(
quest.id,
textwrap.fill(
quest.description,
width=60, subsequent_indent="\t "
)
)

msg += (
"There are {} labors in the Quest. "
"They were started with the event \"{} {}.\""
).format(
len(quest.labors),
creation_event_type.category,
creation_event_type.state,
)

email_message(
quest.creator, "Quest {} started".format(quest.id),
msg
)
return quest

def check_for_victory(self):
Expand Down
8 changes: 6 additions & 2 deletions hermes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ def email_message(recipients, subject, message):
recipients = recipients.split(",")
if isinstance(settings.email_always_copy, basestring):
extra_recipients = settings.email_always_copy.split(",")
else:
extra_recipients = [settings.email_always_copy]

msg = MIMEText(message)
msg["Subject"] = subject
msg["From"] = "hermes@localhost"
msg["From"] = settings.email_sender_address
msg["To"] = ", ".join(recipients)
if extra_recipients:
msg["Cc"] = ", ".join(extra_recipients)

try:
smtp = smtplib.SMTP("localhost")
smtp.sendmail(
settings.email_sender_address, recipients, msg.as_string()
settings.email_sender_address,
recipients + extra_recipients,
msg.as_string()
)
smtp.quit()
except Exception as exc:
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.0"
__version__ = "0.2.1"

0 comments on commit dfdad2a

Please sign in to comment.