Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
To all the dumb spammers and legitimate info brokers out there, this is the most simple code snippet I could write in affordable time.
0.
1a. Extract the Python module to <profile>/Scripts/python Download the attachment and move it to a trusted directory where macros are allowed.
1b. Open the document and edit the SMTP settings on top of the module. Just edit the double-quoted values between the hash fences.
1c. Click the install button.
2. Select a 3-column list of spreadsheet cells: (1)mail addresses, (2)subject line, (3)multi-line body text
The selection must not be a filtered range. Copy any filtered range to another area and select that adjacent range. The selection should not include any header row (column labels). Any columns beyond #3 will be ignored.
3. menu:Tools>Macros>Python... sendMailsFromRangeSelection
You can use Calc's concatenation methods and text functions to compose the messages on the sheet. If you can't even do that, there is not the faintest reason to use a spreadsheet anyway. 2021-08-05: Updated "old style" error handler to work with recent Python versions. Added the 5 seconds sleep by robleyd.
Thank you for posting your work on OO Forum.
I have used your work and found it very useful. I am not an expert in Python script and module so it has been a bit of a learning curve for me.
I would like your help to modify your script if possible.
I have a LibreOffice spreadsheet with 3 columns (TO, SUBJECT and BODY) with hundreds of rows and would like to send an email out one after the other every 5-10 seconds.
This is just a demo how trivial it is to write a Python SMTP mailer and feed it with a DataArray from a sheet, text table, database connection or anything else IF you are familiar with the most fundamental basics of Python, the GUI office and the UNO office. It could be even easier without any office suite, e.g. just from plain text, but any simple UNO object that provides a DataArray or RowSet will work in similar ways.
Most "VBA experts" on this forum do fail because they do not know any Basic language beyond macro recorders and copy&pasting other peoples code. Because they never understood how to fabricate a serial email letter in the GUI of this office suite they can not understand how to do the same with UNO even when they have some example code. They always want other people to write full solutions where they only need to fill in their SMTP credentials.
If you are not interested in this office suite and if you are not familiar with an outdated lingo from the 90ies (Basic) and if you think that UNO is just an organization in New York, you are still able to do fairly complex stuff if you only know a real programming language like Python or Java or anything that uses COM on a Window machine and you need some of the most trivial UNO snippets that get you a DataArray. But you need to know something.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
I've not worked with python before, but a few moments with Mr Duck gave me info about time.sleep() function.
A couple of added lines to Villeroy's python script should do what you need; any errors are not intended but you may keep them I've commented where the additions are.
Sometimes when you send [url=http://net-informations.com/python/net/email.htm]email[/url] using gmail address you can see some error message like this:
It is because Google blocks sign-in attempts from apps which do not use modern security standards (mentioned on their support page). You can however, turn on/off this safety feature by going to the link below: