Home Download Buy Blog Forum Support

is there a SublimeGmail Plugin?

Re: is there a SublimeGmail Plugin?

Postby jbjornson on Fri Nov 29, 2013 3:06 pm

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

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).
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: is there a SublimeGmail Plugin?

Postby aim9x on Fri Nov 29, 2013 4:35 pm

Thanks for the reply! No, it doesn't seem to work.
I figured I needed to change the on_done function. I'm more used to vanilla C programming for microcontrollers and object-oriented programming seems a bit confusing for me ... Especially the lambda function and s variable as it doesn't seem to be defined.

How exactly does
Code: Select all
self.view.window().show_input_panel("Subject:", 'Sent from SublimeText', lambda s, content=text, recipient=to: self.send_gmail(recipient, content, s), None, None)

get the subject string so that it can be attributed to the SUBJECT variable?
aim9x
 
Posts: 3
Joined: Fri Nov 29, 2013 1:15 pm

Re: is there a SublimeGmail Plugin?

Postby aim9x on Fri Nov 29, 2013 7:33 pm

Yeeeah... Sorry... It actually DOES work.
I just kept forgetting to actually input my username/password
Sorry...
aim9x
 
Posts: 3
Joined: Fri Nov 29, 2013 1:15 pm

Re: is there a SublimeGmail Plugin?

Postby jbjornson on Mon Dec 02, 2013 8:40 am

Cool. Glad to help.
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: is there a SublimeGmail Plugin?

Postby Kabouik on Mon Jul 28, 2014 11:00 am

I'm sorry I have to necropost this thread too, but there is apparently an issue with special characters with this plugin. I used the above code (which allows setting an email subject), but will always get an error when using special characters, at least the "ç". It have done several trials prior to identify that this was what caused the error. Any idea on how to solve that?

Also, a few minor issues:
- How can I change the display name of the emails I send? I tried to change the "From:" in the gmail.py to "Firstname Name", but it will still show the username of my Gmail address (which is "firstname.name").
- Any way to send an email in "thread" mode, where all messages with the same subject are put in the same conversation?
- How should I proceed to send an email to multiple recipients? Should I use "," or ";" as a separator, is it supported?

Many thanks in advance for the answers.
Kabouik
 
Posts: 3
Joined: Mon Jul 28, 2014 10:55 am

Re: is there a SublimeGmail Plugin?

Postby jbjornson on Mon Jul 28, 2014 1:47 pm

Kabouik wrote:I'm sorry I have to necropost this thread too, but there is apparently an issue with special characters with this plugin. I used the above code (which allows setting an email subject), but will always get an error when using special characters, at least the "ç". It have done several trials prior to identify that this was what caused the error. Any idea on how to solve that?

Also, a few minor issues:
- How can I change the display name of the emails I send? I tried to change the "From:" in the gmail.py to "Firstname Name", but it will still show the username of my Gmail address (which is "firstname.name").
- Any way to send an email in "thread" mode, where all messages with the same subject are put in the same conversation?
- How should I proceed to send an email to multiple recipients? Should I use "," or ";" as a separator, is it supported?

Many thanks in advance for the answers.


1) Not sure about the unicode issue...I'll have to look closer

2) To set the display name, use the following format for the "from":
Display Name <address@gmail.com>

3) An email will be included in a thread if the subjects are the same (ignoring FW/RE prefix) and the sender is part of the thread
http://www.sensefulsolutions.com/2010/0 ... gmail.html

4) You have to send a list rather that a string:
["first@recipient.com", "second@recipient.com", "third@recipient.com"]

I'll see if I can whip something together to help with this...
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: is there a SublimeGmail Plugin?

Postby Kabouik on Mon Jul 28, 2014 2:58 pm

Thanks a lot for the detailed answer!

1. Hope you'll find something about that, I think accented characters also cause the issue, so that's a big one for my language.

2. Thanks. I've just tried that but it still seems to show my username instead of the display name. I was using an Alias in Gmail so I disabled it and put my Gmail address as default sender again, but still the same issue.

3. Same here: it apparently does not work! Does it, on your side?

4. Thanks a lot!
Kabouik
 
Posts: 3
Joined: Mon Jul 28, 2014 10:55 am

Re: is there a SublimeGmail Plugin?

Postby jbjornson on Tue Jul 29, 2014 9:10 am

Unfortunately I've never actually used the plugin since gmail is blocked from my work computer...I just thought I could help answer your questions :-)
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: is there a SublimeGmail Plugin?

Postby jbjornson on Tue Jul 29, 2014 4:50 pm

Kabouik wrote:2. Thanks. I've just tried that but it still seems to show my username instead of the display name. I was using an Alias in Gmail so I disabled it and put my Gmail address as default sender again, but still the same issue.


2) Try it with quotes around the name:
Code: Select all
"Firstname Name" <example@gmail.com>


(although this won't work if you have unicode characters in your name - you need to encode the name part of the string if you want to do that)

It looks like the creating emails in python that have unicode is a bit difficult. I did some research and tried some things out but it's tough when I can't actually test out the sending code. Even so, I started running into problems as soon as I start using unicode characters...

It's very possibly that my errors are a result of my limited python knowledge - I seem to frequently have issues handling unicode in my plugins.

If I get some time later I'll give it another shot and see if I can get any further.
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: is there a SublimeGmail Plugin?

Postby Kabouik on Tue Jul 29, 2014 5:31 pm

Many thanks again for your time Jbjornson.

2. I've tried with the following, but it did not change anything:
Code: Select all
FROM = '"Firstname Name" <firstname.name@gmail.com>'

Any other uses of the quotes disabled the plugin (Ctrl+Shift+G wouldn't work anymore), like:
Code: Select all
FROM = ''Firstname Name' <firstname.name@gmail.com>'

Code: Select all
FROM = 'Firstname Name' <firstname.name@gmail.com>

Don't bother too much for the display name if you don't find anything about the unicode issue, this is by far the most problematic issue because I cannot use the plugin without unicode characters anyway. Display name and other details might be discussed later if that big one can be solved. :p

I am sorry I don't code, there is no way I can help you with python, I'm afraid. :/
Kabouik
 
Posts: 3
Joined: Mon Jul 28, 2014 10:55 am

PreviousNext

Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests