Gmail sending problems - ssl

So i try smtplib to send gmail automatically, however it fail because of a error, after some checking, my username and pass are True. So i want to ask if there were any mistakes that can lead to this error.
Here is my code, the port is 465 and i don't want anyone know my pass and my username.

The error message "username and password not accepted" is the standard error message you get from the smtp server when sending the users actual google password.
This method of authentication is not acceptable by the SMTP server after (May 30, 2022). Partially due to the removal of Less secure apps & your Google Account mostly because client login is not considered to be secure.
Your options are to to enable 2fa on our google account and use and create an apps password. Simply use it in place of the password in your code.
smtp.login(username, appsPasswrod)
Or to use XOauth2 and authenticate the application.

Create a sendEmail() function, which will help to send emails to one or more than one recipient by calling the function.
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('youremail#gmail.com', 'your-password')
server.sendmail('youremail#gmail.com', to, content)
server.close()
content = "Message to send"
to = "useremail#gmail.com"
sendEmail(to, content)
NOTE: Do not forget to make sure that the smtplib requires 'enable the less secure apps' feature in your Gmail account. Otherwise, the sendEmail function will not work properly..
Create App Password: App Passwords

Related

outgoing mail server on odoo

I have created a record on "ir.mail_server" model which is the outgoing mail server model. configured as:
SMTP Server = smtp.gmail.com
SMTP port = 465
Connection Security = SSL/TLS
Username = my gmail id
Password = my gmail password
tested the connection too gives me a message that"Connection Test Succeeded! Everything seems properly set up! "
previously this was working perfectly
but now when I send an invoice through mail in odoo its sent without error but the recipient is not receiving the mail
any help will be appreciated
Google made updates to the security measures related to app access, so you will not be able to use password. You need to use App Passwords.
In your Google account: Go to Manage your Google Account and select Security:
Turn on 2-Step Verification.
Once the 2-Step Verification turned on, the app passwords option will be enabled and it will be shown under 2-step verification.
Click on App passwords and create an App password and copy the 16 digits password which you got.
Use that 16 digits instead of the password in the Odoo email configuration settings
You can refer to google help for more details about how to create app passwords.

How to generate tokens for mail verify or forgot password without FusionAuth sending mail?

Until yesterday I was using the default mechanism of sending mails like "verify mail" or "forgot password mail". These mails have specials tokens included inside the mail. Both of these endpoint also returns tokens in the response body.
I am now changing the way of sending mails in my application and I want to do it with a separate service. So to activate my users or change their password I need these tokens, but I dont want FusionAuth to send emails. When disabling "verify mails" or "forgot password", calling these endpoints results in a 403. Is there a way to get this tokens without starting the process of sending a mail by FusionAuth ?
The workaround is to add a fake host to the mail config. But it isn't the best idea since I see then an error in logs when generating tokens.
You can use the /api/user/forgot-password API and set sendForgotPasswordEmail to false.
In the Forgot Password API it is the second example :
Start the forgot password workflow using an API key
This will create you a token and will not send the email. You can then build the link yourself and send the email through an external service.

Is there a way to test verification emails using Karate?

The problem I have is that I need to test if user verification is working. We generate a verification token, and an email is sent to the user. Whenever the user clicks on it, it checks if the verification token has expired. I've tried mocking this, but it just won't work. We have an endpoint to verify a user, but we still need the verification token, which is not available on any endpoint.
I think this article may help you: https://www.testingexcellence.com/automated-api-testing-emails-karate/
To summarize:
use the API at http://qamail.ala.se/ to create a test mailbox
initiate the flow that sends the e-mail
use the API to "read" the e-mail and grab the token
EDIT: looks like the link is dead. but you should be able to find similar offerings on the internet. since the source-code seems to be available, it may make sense for you to host this e-mail server somewhere so that it can receive e-mail from whichever system is the sender

PowerShell send SMTP email without (default) authentication

I am attempting to deliver an email to an Exchange-server using PowerShell. My goal is to use plain old SMTP to deliver a message to a local user (mailbox) on the Exchange-server. The Exchange-server is located within the same network and AD-domain as the sending server and as the logged on sending user.
However the user I am sending from does not have access to send emails on that Exchange-server. And PowerShell seems to send authentication using the logged on user credentials by default.
$smtp = new-object Net.Mail.SmtpClient("exchangeserver.mylan")
$smtp.Send($emailFrom, $emailTo, $subject, $message)
I have tried to add $smtp.UseDefaultCredentials = $false before the $smtp.Send(... line without success.
One solution would be to allow this user to send messages on the Exchange server. However the user will change depending on what service is running this script, so I don't want to solve it that way.
Another solution would be to hardcode credentials using something like $smtp.Credentials = New-Object System.Net.NetworkCredential("DOMAIN\user", "password") (also before $smtp.Send(... line). I've had no luck in this either.
The solution I'd really like is to just send email in PowerShell anonymously using good old auth free SMTP.
1) Create new Receive Connector
2) Enable anonymous authentication on it
3) Lock it down to IP address of the computer you are running the script on
I realize this is old, but I'm surprised there isn't an answer here for this. I was confused initially because I have some similar code I wrote in C# and it works just fine. It seems PowerShell will default to using someone's credentials. I won't assume it's who runs the script, but it could be.
When I'm building up the credential object, I pass in a space for the username and password and that seems to work fine.
$credential = New-Object System.Management.Automation.PSCredential (" ", " ")
If I completely leave out the credential part then it will use someone's credentials or something. Until now I was getting the following message:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
I hope this helps someone with such an odd problem.

Pop3Client not authenticating for yahoo

I am trying to retrieve mails from Yahoo account using vb.net. I have used openpopup (Pop3) to do that. Here is my code
Using client As New Pop3Client()<br/>
If client.Connected Then client.Disconnect()<br/>
clientConnect("pop.mail.yahoo.com", 995, true)<br/>
client.Authenticate("Yahoo UserName", "Yahoo Password",AuthenticationMethod.UsernameAndPassword)<br/>
client.Disconnect()<br/>
Return True<br/>
End Using<br/>
I stuck up with the following problem
The server did not accept user credentials while authenticating it, but I am sure that the credentials are correct (I can connect the server with this credentials)
I tried the same code with my gmail, hotmail and aol accounts. It works fine but not for Yahoo. When i try to authenticate with yahoo credentials, I got the following error.
"Server did not accept user credentials".
Please give me the solution for this.
Just to be clear you have Yahoo Plus or whatever they're calling it right? You have to pay for pop access on yahoo. If so are those the same settings that work in outlook or thunderbird?