How to open several gmail accounts via Basic macro on Calc?

Hi, everyone…Would anyone know how to open several email accounts via Basic macro codes? The accounts are stored in cells from A1 to A10 and the passwords are stored in cells from B1 to B10. I wouldn’t even know where to begin and I would appreciate any suggestions you might have.
I thank you very much.

may be have a look into the Python-docs, imap email … …good luck!

Here you wrote email, in the title gmail.
.
If gmail is concerned you have to start with configuring the account to accept other clients than the gmail-app (usually called not-safe, 3rd-party etc.) Itherwise even a perfect python-script will get no data.
Other providers have similiar precautions (have recently helped someone to re-activate access for Thunderbird after using the web.de-app for some months)

Anyone for example: RFC 3501: INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1

Basic has no “standard” library for this. So you would have to communicate with the port directly and do your own implementation of pop3 or imap. This is a text-based dialogue with the server. So not impossible to do. One can even do this by manually for debugging.
.
But usually I’d either recommend to use python or use a mail-program and import or export from/to this.
.
What is your actual goal? Import emails / sending mails / hack an account / get server statistics.

My actual goal ís to open my ten accounts quickly on distinct browser tabs.
I found a solution, but it is written on python…It´s very complicated to compile python macros on calc.
Here is the codes:

# Python 3.8.0
import smtplib
import time
import imaplib
import email
import traceback 
# -------------------------------------------------
#
# Utility to read email from Gmail Using Python
#
# ------------------------------------------------
ORG_EMAIL = "@gmail.com" 
FROM_EMAIL = "your_email" + ORG_EMAIL 
FROM_PWD = "your-password" 
SMTP_SERVER = "imap.gmail.com" 
SMTP_PORT = 993

def read_email_from_gmail():
    try:
        mail = imaplib.IMAP4_SSL(SMTP_SERVER)
        mail.login(FROM_EMAIL,FROM_PWD)
        mail.select('inbox')

        data = mail.search(None, 'ALL')
        mail_ids = data[1]
        id_list = mail_ids[0].split()   
        first_email_id = int(id_list[0])
        latest_email_id = int(id_list[-1])

        for i in range(latest_email_id,first_email_id, -1):
            data = mail.fetch(str(i), '(RFC822)' )
            for response_part in data:
                arr = response_part[0]
                if isinstance(arr, tuple):
                    msg = email.message_from_string(str(arr[1],'utf-8'))
                    email_subject = msg['subject']
                    email_from = msg['from']
                    print('From : ' + email_from + '\n')
                    print('Subject : ' + email_subject + '\n')

    except Exception as e:
        traceback.print_exc() 
        print(str(e))

read_email_from_gmail()

Nonsense…apso exists, and python dont need to compile

I doubt it’s easy.

1 Like

IMHO you are not on the right track here:

  • I don’t see where Calc or LibreOffice is concerned. If it is the only IDE you know, I can understand, but it would add additional obstacles to your real problem.
  • The python code you found and even my “suggestion” to re-program the IMAP-protocol for BASIC will not give you access in an open browser-tab. It is an internal access to retreive data, so you would have also to program the interactive window afterwards… Good luck with this
  • You actually need a toolkit for automation of websites. Look for “webscraping” at google or directly for Selenium.

The easy part is to open the Website, more complicated to find out how the login will be handled.

A random link with a tutorial to start reading: Web Scraping Using Python and Selenium | by Ritik Jain | Python in Plain English

And of course: Wikipedia

Note that most sites don’t easily allow you having several login sessions open at once in the same browser - they use different technologies, like cookies, that would be overwritten each time you login again. So - I would say “I doubt it’s possible at all”.

Actually I assume @Jonjozz has this setup done manually now, so it could be possible…
.
My second assumption is, he asked only for gmail but it may be different providers like yahoo, hotmail, gmx etc.
.
But as somebody already wrote:

As written in my comnent: Don’t use Basic. Try Selenium with an external program like here: How to automate gmail login process using selenium webdriver in java?

If this really has to be started from Calc, create a small wrapper in Badic and call your external program with shell().
.
But my guess is, the only connection to Calc is your current table of website, account and password, wich can be integrated in your Selenium-Skript