Sublime Forum

Is there a SublimeGmail Plugin?

#1

Hi,

I always copy-paste code from sublime to paste in gmail when sending snippets to some user-lists, also sometimes I wrote code directly in the gmail editor.

I want to find (or develop) a plugin to write the email in SublimeText and then call “Gmail: send” on command pallete to send this…

may be the destination can be defined in the command pallete or as some comment in text, also the gmail credential should go in the plugin config file.

It is very easy to send emails using Python+Gmail, but I dont know exactly what I need to be able to do it from Sublime.

Does anybody implemented something like that?

thanks

0 Likes

#2

While not out of the realm of possibility it’s pretty unlikely to gain popular usage, making the effort of development too high.

A plugin of this type would require leveraging GMails OAuth API over IMAP/SMTP. To look into it I suggest starting with Google’s own Python-based documentation. Naturally there’s a security concern involved which makes me think it’s better to look elsewhere or develop this privately where you have better control over its environment.

0 Likes

#3

[quote=“skaet”]While not out of the realm of possibility it’s pretty unlikely to gain popular usage, making the effort of development too high.

A plugin of this type would require leveraging GMails OAuth API over IMAP/SMTP. To look into it I suggest starting with Google’s own Python-based documentation. Naturally there’s a security concern involved which makes me think it’s better to look elsewhere or develop this privately where you have better control over its environment.[/quote]

It is really easy to send emails using gmail and Python

[code]import smtplib

fromaddr = ‘fromuser@gmail.com’
toaddrs = ‘touser@gmail.com’
msg = ‘There was a terrible error that occured and I wanted you to know!’

Credentials (if needed)

username = ‘username’
password = ‘password’

The actual mail send

server = smtplib.SMTP(‘smtp.gmail.com:587’)
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit() [/code]

I just want to know how to use this as a sublime plugin.

0 Likes

#4

I’ll make it for you but I won’t be home for ~3-4 hours.

0 Likes

#5

Oh, it would be cool if you could email the current file as an attachment! Might make it useful

0 Likes

#6

whoops, forgot to do this. I’ll get around to it, though.

0 Likes

#7

I am trying here with no success.

Which methd I have to use to get selected text? self.view.sel() ?

I wanted to have this:

  1. select a text block
  2. Hit the ctrl+shift+G to open Gmail dialog (is it possible?)

Then in dialog I put subject, to, cc, bcc, and a checkbox if I want to include the file as attachment.

even if dialog is not possible, this can be setted in the text with special markup

{{G:to:cc:bcc:subject:True,False}}

Any idea?

0 Likes

#8

self.view.substr(self.view.sel()[0]) gets you the currently selected text.

While you can’t have a custom dialog box with multiple fields, you can use an input panel.

0 Likes

#9

Hey guys.

I don’t know if this has been answered or not… Or the guy sent around the plugin or whatever.

Here is the plugin that does JUST THAT.

Upon pressing ctrl+alt+g it opens up a small input panel where you can enter the destination address and send the selected text:

Google code: code.google.com/p/sublime-gmail-plugin/

Github: github.com/Skarlso/SublimeGmailPlugin

Hope that helped.
Cheers,
Skarlso

0 Likes

#10

Sorry to necropost but here goes:

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?

0 Likes

#11

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).

0 Likes

#12

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

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?

0 Likes

#13

Yeeeah… Sorry… It actually DOES work.
I just kept forgetting to actually input my username/password
Sorry…

0 Likes

#14

Cool. Glad to help.

0 Likes

#15

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.

0 Likes

#16

[quote=“Kabouik”]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.[/quote]

  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
    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…

0 Likes

#17

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!

0 Likes

#18

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 :smile:

0 Likes

#19

[quote=“Kabouik”]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.
[/quote]

  1. Try it with quotes around the name:
"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.

0 Likes

#20

Many thanks again for your time Jbjornson.

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

Any other uses of the quotes disabled the plugin (Ctrl+Shift+G wouldn’t work anymore), like:

FROM = ''Firstname Name' <firstname.name@gmail.com>'
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. :stuck_out_tongue:

I am sorry I don’t code, there is no way I can help you with python, I’m afraid. :confused:

0 Likes