Hmailserver C # SMTP

I'm just trying to get my hmailserver to send mail from my C # program. The part that kills me is the SSL part.

I originally received this error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required. The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.

So, I added: smtp.EnableSsl = true; and now I get Server does not support secure connections.

Here is my code, it drives me crazy. Should I create my own SSL or is there a way to disable SSL on the hmailserver side?

 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); 
+6
source share
5 answers

Well, what you need to do is switch to extended ranges in HMailServer. Create a new IP range, for example, if you are using 192.168.1.2, you should make the range 192.168.1.1-192.168.1.3, and then uncheck all required smtp authentication fields.

Annoying ...

+5
source

To enable a secure connection to send email through your email provider, you need to change the port number.

  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); 
0
source

I had this problem, I used localhost ip and EnableSsl for 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 guide will help you configure custom NetworkCredentials in HMailServer as described above, hope someone helps.

0
source

I stumbled upon this question while trying to configure hMailServer to work with email sending with C #. I tried the following:

  • C # SmtpClient - not working with implicit SSL - see this question and answer
  • AegisImplicitMail from here - failed to get it to work with UTF-8 strings (I have diacritics in my strings)
  • MailKit from here is very powerful and mature, with no problems using it.

I aimed at the following:

  • decent security
  • the ability to send email to major email providers (e.g. Google, Yahoo) and access to Inbox
  • the ability to receive emails from major email providers

C # code

  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 configuration

1) Open ports - 25, 143, 465, 995 are open so you can send and receive email

2) TCP / IP Port Configuration

 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) testing pre C #

Run diagnostics from hMailServer administrator

Use an email client that allows you to manually configure various parameters, such as ports for each protocol, and security. I used Thunderbird. Turn on sending emails to external providers and receiving emails from them (I tried with Gmail).

I did not make changes to the IP ranges and left implicit (My computer and the Internet).

0
source

Despite the fact that 7 years have passed since the publication of the accepted answer, I also supported it at the beginning - I want to emphasize that the proposed solution disables the entire authentication process, which is not necessary. The problem is this:

 smtp.UseDefaultCredentials = false; 

Just delete this line and it should work.

I am posting a working solution here for me (note that I am not using 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); 
0
source

All Articles