Try this (a small change to the gmail.py code from here: https://github.com/Skarlso/SublimeGmailPlugin):
import sublime, sublime_plugin, smtplib
class GmailCommand(sublime_plugin.TextCommand):
to = "example@gmail.com"
text = "selected text"
def on_done(self, to, text):
self.view.window().show_input_panel("Subject:", 'Sent from SublimeText', lambda s, content=text, recipient=to: self.send_gmail(recipient, content, s), None, None)
def send_gmail(self, to, text, subject):
gmail_user = "your@gmail.com"
gmail_pwd = "yourpassword"
FROM = 'your@gmail.com'
TO = '%s' % to] # from input
SUBJECT = subject
TEXT = text
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
#server = smtplib.SMTP(SERVER)
server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
#server.quit()
server.close()
sublime.status_message("Email sent successfully to: %s" % to)
except:
sublime.status_message("There was an error sending the email to: %s " % to)
def run(self, edit):
for region in self.view.sel():
if not region.empty():
# Get the selected text
text = self.view.substr(region)
self.view.window().show_input_panel("To:", 'email@gmail.com', lambda s, content=text: self.on_done(s, content), None, None)
Note: I cannot test this as smtp access is blocked at work but I only changed the on_done function and the signature and subject assignment in the send_gmail function (so it would work as well as it did before).