首页 > 解决方案 > 邮件客户端无法联系 smtp 服务器(用 C++ 编写)

问题描述

我的 smtp 服务器是用 C++ 编写的。邮件客户端采用 HTML 和 JS 格式。我使用 smtpjs 库来发送邮件。用于 Web 服务器的 Apache。但是,邮件客户端根本无法联系到 smtp 服务器。Wireshark 不显示任何 SMTP 交换。

我的 IP 是 192.168.0.105,它位于 NAT 后面。

  1. 我已经尝试过端口转发,并确保在路由器中为端口转发设置了端口 25。但它不起作用。
  2. 路由器上的 DDNS。坦率地说,我不知道如何设置它。无论我尝试什么都没有用。
  3. EmailJs 网站连接到 SMTP 服务器单独检查 SMTP 连接。发生连接超时。

    <!DOCTYPE html>
    
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://smtpjs.com/v3/smtp.js"></script>
    <script>
    function showMsg() {
    $( document ).ready(function() {
    Email.send({
    Host : "192.168.0.105",
    Username : "shwetha@localhost.com",
    Password : "123456",
    To : 'shwetha@localhost.com',
    From : "shwetha@localhost.com",
    Subject : "This is the subject",
    Body : "And this is the body"
    }).then(
    message => alert(message)
    );
    })
    }
    </script>
    

期望是确保客户端联系 smtp 服务器并交换 HELO。

标签: javascriptrouting

解决方案


在 SmtpJS 的 Host 部分中将 IP 更改为 localhost。下一个错误是“服务器不支持安全连接”。这意味着应该在需要弄清楚的 Web 服务器上启用 SSL。

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://smtpjs.com/v3/smtp.js"></script>
<script>
function showMsg() {
$( document ).ready(function() {
Email.send({
    Host : "localhost",
    Username : "shwetha@localhost.com",
    Password : "123456",
    To : 'shwetha@localhost.com',
    From : "shwetha@localhost.com",
    Subject : "This is the subject",
    Body : "And this is the body"
}).then(
  message => alert(message)
);
})
}
</script>

推荐阅读