Detecting a vpn lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- madref · 2023-09-24 14:26 I using the following code to send an email. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function VerzendMail (Const MailAan, Onderwerp: String; Inhoud: TStrings): Boolean;Var Mime : TMimeMess;    P : TMimePart;    B : Boolean;begin  Mime:=TMimeMess.Create;  try    // Zet enkele headers van het bericht.    Mime.Header.ToList.Text := MailAan;    Mime.Header.ReplyTo := SenderName + '<' + SenderEMail + '>';    Mime.Header.Subject := Onderwerp;    Mime.Header.From := SenderName + '<' + SenderEMail + '>';    // Maak een multipart deel aan.    P := Mime.AddPartMultipart('mixed',Nil);    // Als eerste deel de tekst van de mail toevoegen.    Mime.AddPartHTML (Inhoud,P);    // Alle bijlagen toevoegen.//    Mime.AddPartBinaryFromFile (Bijlage,P);    // Na deze code is het MIME bericht klaar. Het bericht dat verzonden    // moet worden, kan nu samengesteld worden door EncodeMessage op te roepen,  // en met SendToRaw te versturen:    // Bericht samenstellen    Mime.EncodeMessage;    // En verzenden met SendToRaw    B := SendToRaw(SenderName + '<' + SenderEMail + '>', MailAan,              smtpHost, Mime.Lines, smtpUser, smtpPassword);    Result := B;  finally    Mime.Free;  end;end;     // VerzendMail  But when I am using a vpn the mail is not send and te app stops How can I detect the vpn and created an 'error message' OR how can I send the email while using the vpn? ---------------------------------------------------------------------- alpine · 2023-09-24 14:44 Quote from: madref on September 24, 2023, 04:26:34 pm*snip* But when I am using a vpn the mail is not send and te app stops How can I detect the vpn and created an 'error message' OR how can I send the email while using the vpn? You should provide more details what is exactly the error and why the app stops. Perhaps your smtp host just can't be resolved? ---------------------------------------------------------------------- Leledumbo · 2023-09-25 04:00 There's no straightforward way. After all, VPN is designed to be an unknown middleman between the client and the server. It will defeat the purpose of a VPN if it can be easily detected. There are some escapes, but they have no guarantee. One relatively easy way is to check your own public IP, as VPN will try to disguise, it's very likely to have an uncommon IP than the one your ISP assigns. You can hit https://ifconfig.me/ip to get it, which will give you a text based response like this: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 103.28.116.101this method is agnostic to the VPN service, but ISPs like to use dynamic public IP and if the VPN server is in the same country, it might be tough to check. The second method is easier, but requires knowledge of specific VPN service. NordVPN, for example, can be easily queried: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $ nordvpn statusStatus: DisconnectedA single line of SysUtils.ExecuteProcess is sufficient. But then again, it has to be adapted to whatever VPN service you use and ensure it has a tool that can give similar output. There are more ways, but they're all more difficult to do, so I suggest just the two above. ---------------------------------------------------------------------- rvk · 2023-09-25 05:47 Quote from: madref on September 24, 2023, 04:26:34 pmHow can I detect the vpn and created an 'error message' OR how can I send the email while using the vpn? You are focusing on the wrong thing. There is no problem sending an e-mail when on a vpn (at least not for me). It just happens that you have a problem sending e-mail when you are an a vpn but that's not the main cause. So you can program in detection but that's not going to help you (it wil in your specific case but it will also prevent sending mail when on a vpn where it does work). So focus on the real reason your sending fails and handle that. It will make your program more stable because then it will also handle other exceptions where mail might fail. So give more info about the crash. If it doesn't crash but just stops try to run the app in the IDE. It will give you a more clear error when debugging (and on what place in your program). ---------------------------------------------------------------------- af0815 · 2023-09-25 05:57 A simple answer - store the mail, check if the mailserver is reachable before you send, if not say this problem happens to the user. And ask him for resend, if the mailserver is reachable. ---------------------------------------------------------------------- madref · 2023-09-27 10:31 I let the program run for 60 seconds and I finally got an error code and I already was so smart to generate a fault message. Which error I got I don't know because the SendToRaw generates it. But I will investigate it further