|
Mail clipboard as HTML using LuaSocket
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Morat
(18 posts) bio
|
| Date |
Fri 22 Jan 2010 09:07 AM (UTC) [ quote
] Amended on Sat 23 Jan 2010 07:15 AM (UTC) by Morat
|
| Message |
This script sends the clipboard as HTML to an outgoing mail SMTP server (without SSL).
You can use the "Edit > Copy" or "Edit > Copy as HTML" command to set the clipboard.
local s = GetClipboard()
if not string.match(s, "Produced by MUSHclient") then
s = '<pre><font size=2 face="Fixedsys">' .. FixupHTML(s) .. "</font></pre>"
end
local smtp = require("socket.smtp")
local r, e = smtp.send {
from = "<sender@example.com>",
rcpt = "<recipient@example.com>",
source = smtp.message {
headers = {
from = "MUSHclient " .. GetInfo(72),
subject = GetInfo(2),
to = GetInfo(3),
["content-type"] = 'text/html; charset="us-ascii"'
},
body = '<html><body bgcolor="#000000" text="#C0C0C0">' .. s .. "</body></html>"
},
server = "smtp.example.com",
port = "25"
}
if r then
AnsiNote("\\n" .. ANSI(33) .. "Mail Sent")
elseif e then
AnsiNote("\\n" .. ANSI(33) .. "Error: " .. e)
end
EDIT: added HTML tag
Is there a way to copy the entire buffer as HTML from a script?
reference:
Communicating with the Internet (with LuaSocket)
http://www.gammon.com.au/forum/?id=8319
LuaSocket SMTP
http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/smtp.html | top |
|
| Posted by |
Nick Gammon
Australia (18,797 posts) bio
Forum Administrator |
| Date |
Reply #1 on Fri 22 Jan 2010 08:12 PM (UTC) [ quote
] |
| Message |
Morat said:
Is there a way to copy the entire buffer as HTML from a script?
No I don't think so, and it could potentially get very large. You could:
However that is deferred to the next event loop (that is, you couldn't do DoCommand ("CopyAsHTML") and then *immediately* email the results). Also you would need to establish a start and end selection point.
To do the whole thing yourself you would need to do roughly what CopyAsHTML does (see the source code), possibly using FixupHTML to handle < and > symbols inside the buffer. If monochrome was OK, it would be simple enough. To do colours, well check out the source. ;)
Basically it takes each style run and puts <span> directives around it to handle the colours.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
| Posted by |
Nick Gammon
Australia (18,797 posts) bio
Forum Administrator |
| Date |
Reply #2 on Sat 23 Jan 2010 01:23 AM (UTC) [ quote
] Amended on Sat 23 Jan 2010 01:24 AM (UTC) by Nick Gammon
|
| Message |
It works reasonably well once you fill in the sender and recipient address, but you may want to work on the format a bit. My spam checker at the server reported:
pts rule name description
---- ---------------------- -------------------------------------------- ------
3.6 TVD_SPACED_SUBJECT_WORD3 TVD_SPACED_SUBJECT_WORD3
0.0 HTML_MESSAGE BODY: HTML included in message
1.7 MIME_HTML_ONLY BODY: Message only has text/html MIME parts
1.1 HTML_MIME_NO_HTML_TAG HTML-only message, but there is no HTML tag
The original message was not completely plain text, and may be unsafe to
open with some email clients; in particular, it may contain a virus,
or confirm that your address can receive spam. If you wish to view
it, it may be safer to save it to a file and open it with an editor.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
1,945 views.
Reply to this subject
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )