[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Mail clipboard as HTML using LuaSocket

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Mail clipboard as HTML using LuaSocket
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date 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
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date 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:


DoCommand "CopyAsHTML"


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
[Go to top] top

Posted by Morat   (18 posts)  [Biography] 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
[Go to top] 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,917 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]