Hmailserver C#SMTP

时间:2013-02-11 00:34:37

标签: c# smtp hmail-server

我只是想让我的hmailserver从我的C#程序发送邮件。杀死我的部分是SSL部分。

我最初收到此错误:The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.

所以我补充说:smtp.EnableSsl = true;现在我得到Server does not support secure connections.

这是我的代码,这让我疯了。我是否必须创建自己的SSL或者是否有办法在hmailserver端禁用SSL?

MailMessage mail = new MailMessage("jlnt@ademo.net", "com", "NEW Item", emailBody);
SmtpClient smtp = new SmtpClient("1.1.1.250");
smtp.Port = 25;
NetworkCredential login = new NetworkCredential("ja@test.net", "dg");
smtp.Credentials = login;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Send(mail);

5 个答案:

答案 0 :(得分:5)

啊,好的,您需要做的是在HMailServer中转到advanced-ip范围。创建一个新的IP范围,例如,如果您是192.168.1.2,则必须设置范围192.168.1.1-192.168.1.3,然后在底部取消选中所有必需的smtp身份验证框。

...恼人的

答案 1 :(得分:0)

要启用安全连接以通过电子邮件提供商发送电子邮件,您必须更改端口号。

       MailMessage mail = new MailMessage("jlnt@ademo.net", "com", "NEW Item", emailBody);
        SmtpClient smtp = new SmtpClient("1.1.1.250");
        //smtp.Port =25;
        smtp.Port =587;
        NetworkCredential login = new NetworkCredential("ja@test.net", "dg");
        smtp.Credentials = login;
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        smtp.Send(mail);   

答案 2 :(得分:0)

我遇到了这个问题,我所做的是使用localhost ip和EnableSsl为false

SmtpClient smtpClient = new SmtpClient();
            smtpClient.Host = "127.0.0.1";
            smtpClient.Credentials = new NetworkCredential("test@123test.com", "pass123");
            smtpClient.EnableSsl = false;

         // then your other statements like: from, to, body, to send mail

this指南将帮助您在上面使用的HMailServer中设置自定义NetworkCredentials,希望能帮助某人。

答案 3 :(得分:0)

在尝试将hMailServer配置为从C#发送电子邮件时,我偶然发现了这个问题。我尝试过以下方法:

  • C#SmtpClient - 不适用于隐式SSL - 请参阅此question并回答
  • 来自here的AegisImplicitMail - 无法使用UTF-8字符串(我的字符串中有变音符号)
  • 来自here的MailKit - 非常强大且成熟,使用它没有任何问题

我的目标是:

  • 体面的安全
  • 能够向主流电子邮件提供商(例如Google,Yahoo)发送电子邮件并到达收件箱
  • 能够接收来自主流电子邮件提供商的电子邮件

C#代码

    public void MailKitSend(string senderEmail, string senderName, string subject, string bodyText, string receivers, string receiversCc)
    {
        // no receivers, no e-mail is sent
        if (string.IsNullOrEmpty(receivers))
            return;

        var msg = new MimeMessage();
        msg.From.Add(new MailboxAddress(Encoding.UTF8, senderName, senderEmail));
        msg.Subject = subject;
        var bb = new BodyBuilder {HtmlBody = bodyText};
        msg.Body = bb.ToMessageBody();

        IList<string> receiversEmails = receivers.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
        foreach (string receiver in receiversEmails)
            msg.To.Add(new MailboxAddress(Encoding.UTF8, "", receiver));

        if (!string.IsNullOrEmpty(receiversCc))
        {
            IList<string> receiversEmailsCc = receiversCc.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            foreach (string receiverCc in receiversEmailsCc)
                msg.Cc.Add(new MailboxAddress(Encoding.UTF8, "", receiverCc));
        }

        try
        {
            var sc = new MailKit.Net.Smtp.SmtpClient();
            if (!string.IsNullOrWhiteSpace(SmtpUser) && !string.IsNullOrWhiteSpace(SmtpPassword))
            {
                sc.Connect(SmtpServer, 465);
                sc.Authenticate(SmtpUser, SmtpPassword);
            }

            sc.Send(msg);
            sc.Disconnect(true);
        }
        catch (Exception exc)
        {
            string err = $"Error sending e-mail from {senderEmail} ({senderName}) to {receivers}: {exc}";
            throw new ApplicationException(err);
        }
    }

hMailServer配置

1)已打开的端口 - 25,143,465,995已打开,以确保您可以发送和接收电子邮件

2) TCP / IP端口配置

SMTP / 0.0.0.0 / port 25 / no security (allow receiving start process)
SMTP / 0.0.0.0 / port 465 / SSL/TLS security (must define a SSL certificate)
POP3 / 0.0.0.0 / port 995 / SSL/TLS security (use the same SSL certificate)

3)预C#测试

从hMailServer Administrator

运行诊断程序

使用允许手动配置各种设置的电子邮件客户端,例如每个协议的端口,安全性。我用过Thunderbird。包括向外部提供商发送电子邮件和接收电子邮件(我已尝试使用Gmail)。

我没有对IP范围进行任何更改,只留下了隐含的内容(我的电脑和互联网)。

答案 4 :(得分:0)

虽然已经过了7年,但是我已经公布了接受的答案 - 我也在一开始就对它进行了评价 - 我想强调一下,建议的解决方案会禁用整个身份验证过程,这是不必要的。问题在于:

smtp.UseDefaultCredentials = false;

只需删除该行即可。

我在这里发布了适合我的工作解决方案(注意我没有使用SSL):

    MailMessage mail = new MailMessage("a1@test.com", "foooo@gmail.com");
    SmtpClient client = new SmtpClient();
    client.Credentials = new NetworkCredential("a1@test.com", "test");
    client.Port = 25;
    client.EnableSsl = false;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
    client.Host = "...IPv4 Address from ipconfig...";
    mail.Subject = "this is a test email.";
    mail.Body = "this is my test email body";
    client.Send(mail);