question

SanelPandzic-5621 avatar image
0 Votes"
SanelPandzic-5621 asked JoseZero-8614 answered

Problem sending by email

I installed the latest version of the MailKit package, I figured out those methods in MailKit. I first tried to make the application complete for sending emails, but it could not be sent, so I later took the code from the internet and pasted the code. I researched and saw that I needed to make an SMTP server, so I could send emails through the program. I'm interested in how to make an SMTP server, if it can be free, or must be purchased, I tried "smtp.gmail.com", but it throws me this error "System.Net.Sockets.SocketException: 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because the connected host has failed to respond 142.250.102.108:587 '". I’ve searched the internet, and it’s paid almost everywhere

I tried to make a free google SMTP server, I found on youtube that it can, but again this error occurs to me, that server that I made works, I tried through the "SMTP online test", but only here it will not.


  var message = new MimeMessage();
                 message.From.Add(new MailboxAddress("Test", "pandzicsanel7@gmail.com"));
                 message.To.Add(new MailboxAddress("Test", "pandzicsanel7@gmail.com"));
                 message.Subject = "How you doin'?";
    
                 message.Body = new TextPart("plain") { Text = "Test" };
               
                 using (var client = new SmtpClient())
                 {
                        
                 client.Connect("smtp.gmail.com", 587, false);
    
    
                   
                 client.Authenticate("pandzicsanel7@gmail.com", "");
    
                 client.Send(message);
                     client.Disconnect(true);
dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SanelPandzic-5621, as others said, we have to enable Less Secure Sign-In (or Less secure app access) in your google account. You can refer to the question to know how to do it.


0 Votes 0 ·
SethWH avatar image
0 Votes"
SethWH answered JoseZero-8614 commented

I use gmail for various email notification redirects. You have to enable "less secure apps" for it to work in your gmail security settings. Every now and then you'll get notifications about your app trying to email out and you have to approve again. Also, please delete your password in your script if it's the valid one.

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SethWH I just did that, as soon as I turned on less secure apps, I got a mail that someone had turned on less secure apps, so I allowed that change, so I tried to send mail through the program again and got this error. The error is the same as the one above, except that this address "66.102.1.109:587" is now in error, and this address was "142.250.102.108:587"

0 Votes 0 ·
JoseZero-8614 avatar image JoseZero-8614 SanelPandzic-5621 ·

@SanelPandzic-5621, some SMTP & Google basics
In the beginning any SMTP server was accepting email from any source, but due increasing of SPAM, SMTP become to accept mails "only" from authenticated users, then later become to check Black Lists like Spamhaus before accept mails between SMTP servers. The other measure in place is Reverse DNS checking.
Of course you can have a Windows or Linux with an SMTP Service running, but you need to have an fixed IP and ask for Provider Register a Reverse DNS to your IP, so your SMTP Server can exchange mails with others SMTP servers around the web. I´m sure this not what you want.

Enable "less secure apps" on Google account is just to disable 2 factor authentication, have in mind you can´t do such authentication (2FA) over lines of code.

Please post the exception message you are getting "as is", it will tell what is the real issue.

Google SMTP has multiple IP address, that´s why you getting error from distinct address

0 Votes 0 ·

@JoseZero-8614
Okay, what exactly do I need to do now to fix this? I am new to programming.

0 Votes 0 ·
Show more comments
falconitservicesinc avatar image
0 Votes"
falconitservicesinc answered

Hello Sanel,

If you have access to Windows Server, it has an SMTP service you can enable. The setup instructions are on the link below, just skip past the SharePoint setup and look at the SMTP setup part. It's very easy to set up and very reliable.

https://www.falconitservices.com/sharepoint-2019-and-sql-server-installation-step-by-step/

Cheers,

Miguel Fra
https://www.falconitservices.com

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JoseZero-8614 avatar image
0 Votes"
JoseZero-8614 answered

@falconitservicesinc, a Windows SMTP server, initially, will help just for local test. In production you need a fixed IP address and a Reverse DNS at provider, other than SMTP around web will not accept messages coming from your server

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.