sách gpt4 ai đã đi

email - 使用 luasocket smtp 和 ssl 发送电子邮件

In lại 作者:太空宇宙 更新时间:2023-11-03 13:03:29 26 4
mua khóa gpt4 Nike

我一直在尝试使用帖子中描述的代码发送电子邮件:

lua send mail with gmail account

代码由Michal Kottman重复如下:

-- Michal Kottman, 2011, public domain
local socket = require 'socket'
local smtp = require 'socket.smtp'
local ssl = require 'ssl'
local https = require 'ssl.https'
local ltn12 = require 'ltn12'

function sslCreate()
local sock = socket.tcp()
return setmetatable({
connect = function(_, host, port)
local r, e = sock:connect(host, port)
if not r then return r, e end
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1'})
return sock:dohandshake()
kết thúc
}, {
__index = function(t,n)
return function(_, ...)
return sock[n](sock, ...)
kết thúc
kết thúc
})
kết thúc

function sendMessage(subject, body)
local msg = {
headers = {
to = 'Your Target ',
subject = subject
},
body = body
}

local ok, err = smtp.send {
from = '',
rcpt = '',
source = smtp.message(msg),
user = 'username',
password = 'password',
server = 'smtp.gmail.com',
port = 465,
create = sslCreate
}
if not ok then
print("Mail send failed", err) -- better error handling required
kết thúc
kết thúc

如果我从 gmail 发送邮件,该代码可以正常工作。但是,当我使用 smtpout.secureserver.net(同一端口)的 godaddy smtp 服务器时,它无法发送消息。我刚收到错误代码 550。 请任何人帮助我弄清楚如何进行这项工作。

Cảm ơn.

1 Câu trả lời

感谢这篇文章,它成功了:

Trying to send email to Google through in Python, email being denied

我只是更改了代码以在标题表中添加 from 字段,如下所示:

-- Michal Kottman, 2011, public domain
local socket = require 'socket'
local smtp = require 'socket.smtp'
local ssl = require 'ssl'
local https = require 'ssl.https'
local ltn12 = require 'ltn12'

function sslCreate()
local sock = socket.tcp()
return setmetatable({
connect = function(_, host, port)
local r, e = sock:connect(host, port)
if not r then return r, e end
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1'})
return sock:dohandshake()
kết thúc
}, {
__index = function(t,n)
return function(_, ...)
return sock[n](sock, ...)
kết thúc
kết thúc
})
kết thúc

function sendMessage(subject, body)
local msg = {
headers = {
from = "",
to = 'Your Target ',
subject = subject
},
body = body
}

local ok, err = smtp.send {
from = '',
rcpt = '',
source = smtp.message(msg),
user = 'username',
password = 'password',
server = 'smtp.gmail.com',
port = 465,
create = sslCreate
}
if not ok then
print("Mail send failed", err) -- better error handling required
kết thúc
kết thúc

关于email - 使用 luasocket smtp 和 ssl 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29312494/

26 4 0
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com