I would like to verify if an email is send and control his content.
I have seen that ImapLibrary can do the job but I must have a mail client to check the received mail ?
Can I do the same job with an another address (yopmail, for example) ?
On my local machine, I have a client but when I will run the test since the PIC (Continuous Integration Platform), I don’t see how can I do.
If I can have a solution which works on the both platform (windows and linux), I will be happy
I can’t see that you need an additional mail client, though I can’t see that it will prevent you from having one either, this library should act as an imap client, it would be the same as if you had 2 email clients installed on 2 machines both accessing the same account.
Did you install this using pip?
Also does your mail server support imap? I know with Gmail you need to enable it through a setting.
*** I’ve never used this library myself, so am just answering based on what I see in the documentation.
I have installed the library and began to use it like this to open the mailbox :
Open Mailbox host=imap.gmail.com user=USER password=PASSWORD port=PORT
But I have an error => ConnectionRefusedError: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée.
I have activated IMAP access on Gmail. I see on the Google parameter that the IMAP connection should use the SSL : is this the solution ? How to fix it ?
Otherwise, you think that if I use “Browser library”, I can connect to the mailbox and check his content ?
I have made the modification but I have always an error :
Open Mailbox host=imap.gmail.com user=USER password=PASSWORD port=PORT is_secure=True
FAIL : TimeoutError: [WinError 10060] Une tentative de connexion a échoué car le parti connecté n’a pas répondu convenablement au-delà d’une certaine durée ou une connexion établie a échoué car l’hôte de connexion n’a pas répondu
That error according to google translate says
“A connection attempt failed because the connected party did not respond properly after a certain amount of time or an established connection failed because the connecting host did not respond”
which makes me wonder if you used the correct port number or if need to configure a proxy server?
I can’t see any mention of proxy in the documentation, so i’m not sure how to do that, you might have to contact the maintainer of the library if that’s the problem.
did you manage to connect an email client by imap to this server successfully? sometimes doing that will highlight where any issues are and when you have it working you’ll have the settings you need for this library.
Thanks you for your answer, Dave.
I try to contact the maintainers but I didn’t found their email address on the pipy page => robotframework-imaplibrary · PyPI
I don’t try to connect an email client by imap because my client belongs to my organisation and I can’t modify its parameters.
Perhaps I’m going to create a yopmail account to connect with my browser and make check with SeleniumLibrary… but it will not be very optimal, no?
If you can install software on your work computer, but don’t want to mess up your work email client, try installing something like thunderbird or similar to check if you can access the imap account.
If you can’t install any software, look around and you might find an email client in Java or Python that you might be able to use for testing.
If all that fails yopmail and SeleniumLibrary or Browser Library might be your best bet. you could also try accessing yopmail with requests library, yopmail looked like it had very simple html so if you can read what you need out of it’s emails with requests library this would be a nice low overhead solution.
I adjusted the example from the smtplib to send an email to yopmail (see yopmail.py below).
Then tried to access it via requests library, that was quite difficult as there is a lot of javascript generated id’s that need to be sent so, while I could login i was getting 400 errors on loading the inbox
Then I tried to read the email with SeleniumLibrary, as expected that was easy (example below
yopmail.robot
*** Settings ***
Library SeleniumLibrary
*** variables ***
${yopmail_user} example13
${yopmail_url} https://yopmail.com/
*** Test Cases ***
yopmail example
Open Browser ${yopmail_url} ff
# //input[@name='login']
Input Text //input[@name='login'] ${yopmail_user}
# //div[@id="refreshbut"]/button
Click Element //div[@id="refreshbut"]/button
# ifinbox
Select Frame ifinbox
Click Element //div[text()='Example for John']/..
# ifmail
Unselect Frame
Select Frame ifmail
${mailbody}= Get Text //div[@id='mail']/pre
Should Contain ${mailbody} Example13
yopmail.py
# example13@yopmail.com
import smtplib
def prompt(prompt):
return input(prompt).strip()
# fromaddr = prompt("From: ")
fromaddr = "example13@example.com"
# toaddrs = prompt("To: ").split()
toaddrs = "example13@yopmail.com"
# print("Enter message, end with ^D (Unix) or ^Z (Windows):")
subject = "Example for John"
# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n"
% (fromaddr, ", ".join(toaddrs), subject))
line = "this is a test message for Example13"
# while True:
# try:
# line = input()
# except EOFError:
# break
# if not line:
# break
# msg = msg + line
# msg = msg + "\r\n.\r\n" + line + "\r\n.\r\n"
msg = msg + line + "\r\n\r\n.\r\n"
# msg = "this is a test message for Example13"
print("Message length is", len(msg))
# server = smtplib.SMTP('localhost')
server = smtplib.SMTP('yopmail.com')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
That should give you enough to get something working,
Hi @damies13
I created one cloud account
it sent email verification code to Gmail account
I need to copy that verification code which they sent to mail Any idea on how to open a mail and copy the verification code
Written code like this to open mail using SeleniumLibrary library
SeleniumLibrary
This is a really old thread, probably would have been better to start a new one.
Once you have the email body you can use Get Regexp Matches to extract the verification code.
Scripting GMail with SeleniumLibrary is likely to cause you a lot of pain with the reCAPTCHA prompts, so you would probably be better to use imap to access your gmail account, though I’ve never done this with RF
login manually to GMail and go to settings, then enable IMAP as below:
A final tip, if you use xpaths like this: /div[1]/div/div[1]/input you are asking for trouble as sites often change and you’ll be constantly updating your broken xpaths. There is a really good XPath Tutorial here for learning how to write good xpaths.
Worth pointing out that for imap library to work, one has to generate “app password” in the gmail settings. That password will be used for auth instead of user’s own password.