Abaksoft Posted February 6, 2020 Posted February 6, 2020 Dear Unigueers, There are many possibilities to send email with Delphi. The easiest way a found, is via gmail Server. Although I found a few portions of code on the forum, no one has detailed the important steps to make it work. So, here is a sample where you will for sure understand : //================================== // Sending email with gmail Server : //================================== // This is a compilation of code providing from Web and Unigui Forum. // So thx to all of them // Step by Step : //1. if you have not a gmail account, Create it. //2. Important : // - Enter in your Personnal Setting (gmail) and look for "Security" // - Activate something like : "Allow less secure apps " //3. Download (and Copy on the same executable folder ...\debug\) the two open SSL Libraries : libeay32.dll and ssleay32.dll. (you can find them in C:\...FmSoft\..\SSL) Important: - if your unigui app is deployed on iis ( ISAPI), then copy them on system32 or syswow64 . - if it is deployed as Service / hyperserver, then keep them behind your exe file (same directory) //4. Connect internet and launch this program Have Fun Sending_Email.zip Edit : On Unit Cls_email : Modify this with your emal adress : IdSMTP.Username :='MyAdress@gmail.com'; // (1) IdSMTP.Password :='Mypw'; IdMessage.From.Address :='MyAdress@gmail.com'; // the same in (1) Personnal Setting (gmail) " Allow less secure apps " : 4 1 2 Quote
Pep Posted September 22, 2020 Posted September 22, 2020 Sample Application Sending a gmail with: Multiple Address HTML Body Attach File Many thanks to Abaksoft! for his detailed post and sample. // Use sample: Gmail := TGmail.Create('YourAccount@gmail.com', 'App password', 'From you/company'); try try Gmail.Connect; Gmail.Send(['useremail@gmail.com'], 'Subject', 'PlainBody', 'htmlBody', 'AttachmentFile'); Gmail.Send(...); Gmail.Send(...); except on E: Exception do ShowMessage(E.Message); end; finally GEmail.Free; end; Atthached file: Sending_gmail.7z 4 Quote
mierlp Posted September 24, 2020 Posted September 24, 2020 Hi, Be aware that when you send a lot of mail VIA gmail (bulk mail), you will soon be blocked because of spam. Much is then a relative concept because mail is monitored on the ip address / domain from which it is sent, number per minute, hour, etc., sender and replay address, etc. If you really want to use it for business to send mail from your application, you can better: 1. send mail from your own domain, so via the domain where your application is started.hosted 2. use an smtp / relay server 3. send mail via an account of the customer Option 1: send from your own domain You can then create an email address for each customer. Suppose your application domain name is "myapp.com". You have 2 customers who use your application. These are the companies: - company-X (have their own website / mail) - company-Z (have their own website / mail You now create an e-mail address for every customer, namely: - company-X@myapp.com - company-Y@myapp.com When the company uses the e-mail functionality within your application, they use the above e-mail address. Mail will now be sent FROM your own domain name WITH the same domain e-mail address, namely @ myapp.com The next step is to ensure that when a reply is given to this e-mail, it also reaches the relevant company. After all, one answers to Company-X@myapp.com and the mail ends up in your mail environment. You now put a forward line on the mailbox of company-X@myapp.com whereby the mail is forwarded to an email address of the company, for example info@company-X.com. Now the mail is forwarded to the company and the communication takes place directly between company and customer who has replyd on that mail. Company-X must, however, submit an spf record in their web environment take from myapp.com. This indicates that company-X trusts myapp.com when sending e-mail. Option 2: use a relay server This is the most reliable way of sending mail. A smtp provider has everything set up to send mail optimally, continuously adapting the changing mail rules of eg gmail, hotmail, outlook, etc. All you have to do is create accounts per customer, etc. Examples of smtp / relay server providers are for example (there are in every country): - https://www.sendinblue.com/ - https://www.mailchimp.com/ - https://www.serversmtp.com/ - https://sendgrid.com/ - https://www.flowmail.com You then pay an x amount for an x number of mails to be sent per month, usually it starts at 15.000-20,000 per month. Option 3: use mail server client This option is also applied, but may result in mail being seen as a spam. You ask your customer to create an email address with a password. What you actually do is use this data to log in to the mail server of the customer and send mail via that mail server. All 3 options have advantages and disadvantages. Sending mail from a different mail address than your domain (where your application is located) is often seen as spam. Especially when you are going to send multiple mails to the same e-mail domain within a certain time. This specific time is different for each provider (gmail, hotmail, outlook). Do not forget to include the correct header information in your mail, especially when you send mail using options 1 and 2. Header information is important because the domain is often mentioned there and then you run the risk that app domain and mail domain are different to be. You also have a number of other settings such as Dkim, Dmarc, Tls that affect the security of mail. Regards Peter 1 2 Quote
mierlp Posted September 26, 2020 Posted September 26, 2020 Hi Mohammed, Looks good and neat. But beware if you are going to send this on behalf of rivierea-tours from YOUR gmail account WITH THE SENDER read@riviera-tours.net. Then it will be seen as spam. Also when the recipient gives a replay, the mail will not arrive at read@riviera-tours.net if nothing arranges. Maybe it is an example and in practice it is arranged differently A number of guidelines apply to (bulk) mail: - link to domains, not IP addresses in email html body. - do not include JavaScript in email html body. - do not include embedded Object (ActiveX / Flash) in email html body. - don't include HTML forms in email html body. Providers such as hotmail, gmail, yahoo impose many restrictions on sending e-mail. You do not have this when you send mail from your own domain or take one of the options from my previous message Some guidelines https://support.google.com/mail/answer/81126 https://support.google.com/mail/thread/9912589?hl=en https://help.yahoo.com/kb/emails-arent-received-yahoo-mail-sln28074.html Regards Peter Quote
mierlp Posted September 26, 2020 Posted September 26, 2020 Hi We have a site in the Netherlands, also in English, where you can check whether your internet domain and e-mail comply with the internet standards worldwide https://en.internet.nl/ Them most common internet standard for mail are: - dnssect - dmarc, dkim en spf - starttls / tls Quote
+228uniGui Posted June 12, 2021 Posted June 12, 2021 Hi everyone ! I 'm trying to integrate Email option in my final examination app . @pep what is the TGmail class in delphi (I'm new in delphi programming )? can you send the attached files again please? thanks for all . Quote
jrp Posted September 19, 2022 Posted September 19, 2022 On 2/6/2020 at 10:58 PM, Abaksoft said: Personnal Setting (gmail) " Allow less secure apps " : Hello everyone, From May 30, 2022 Google had disabled this feature (allow less secure apps). The sample app will display a message that "Username and Password not accepted". Do you have any workaround for using GMail? Thank you Quote
DFong Posted September 19, 2022 Posted September 19, 2022 I found that using an app password on your Gmail account will get around this problem: https://support.google.com/mail/answer/185833?hl=en-GB 1 Quote
jrp Posted September 20, 2022 Posted September 20, 2022 Hello DFong, Thank you for your answer. Could you please explain further, where to use the app password? I followed the link you gave, and now I have the 16 digit password. But I don't know where to use the password: If I use the password to login to my Google account in FireFox, and send email with the sample from Abaksoft from another tab in FireFox, it doesn't work If I use the password as SMTP password for smtp.google.com, it doesn't work. Thanks again. Quote
jrp Posted September 20, 2022 Posted September 20, 2022 Hello, I solved my problem by deleting the app password, and create another one. I really don't know what is wrong with the first app password. But the second one worked! I use the app password as the SMTP password in Abaksoft's sample successfuly. So if anyone failed to use the app password, create a new one 😃 1 hour ago, jrp said: Hello DFong, Thank you for your answer. Could you please explain further, where to use the app password? I followed the link you gave, and now I have the 16 digit password. But I don't know where to use the password: If I use the password to login to my Google account in FireFox, and send email with the sample from Abaksoft from another tab in FireFox, it doesn't work If I use the password as SMTP password for smtp.google.com, it doesn't work. Thanks again. Quote
DFong Posted September 20, 2022 Posted September 20, 2022 Yeah, it's been awhile but I somehow recall having the same behavior when I first tried it months ago as I also needed to create a password twice. At the time, I thought it may have had something to do with the app password being machine specific, but I was never able to reproduce it as I'm successfully using the latest app password from 2 different machines. Glad to hear it's working for you! 1 Quote
fraxzi Posted March 28, 2023 Posted March 28, 2023 Hi All Gurus, How about sending email via Office 365? -Frances 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.