aim9x wrote:I find this plugin very useful. I'd like to be able to add a input panel that allows you to customize/enter the subject line. How should I go about doing that?
Try this (a small change to the gmail.py code from here: https://github.com/Skarlso/SublimeGmailPlugin):
- Code: Select all
import sublime, sublime_plugin, smtplib
to = "firstname.lastname@example.org"
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 = "email@example.com"
gmail_pwd = "yourpassword"
FROM = 'firstname.lastname@example.org'
TO = ['%s' % to] # from input
SUBJECT = subject
TEXT = text
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
#server = smtplib.SMTP(SERVER)
server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work!
server.sendmail(FROM, TO, message)
sublime.status_message("Email sent successfully to: %s" % to)
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@example.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).