Accessing link in email message using gmail api & Cypress - gmail-api

hope u all safe ,
i am doing e2e automated test by Cypress , and i have problem to access link in the received email (Gmail account)from a specific email address. So far using GMAIL api I am able to get the email id using Cy.task
testCase 1. : visit signup page and fill information .// Passed
testCase 2 : ensure that email has received by using gmail-tester library // Passed
testCase 3: the problem is here ===>> click on CTA confirm ur email address and it should direct me to confirmation page Or extract href then cy.visit(href)
**href**="http://post.spmailtechnol.com/f/a/mD0QS83FHCNqxzGZpDJgfg~~/AALxrAA~/RgRgYvyvP0T3aHR0cHM6Ly9uZXh0LWRldi50YWphd2FsLmNvbS9lbi91c2VyL3ZlcmlmeT90b2tlbj00ZjM5Y2I0ZC0yZjU2LTQxYmItOWFlNC0yMDFjN2Y3ZTAyM2UmcmVxdWVzdElkPWM2ZGNiOTEwLThkZWQtNDFhYy05ODQ0LWJjMTdlZWFmOTEyNyZ1dG1fc291cmNlPXRyYW5zYWN0aW9uYWwmdXRtX21lZGl1bT1lbWFpbCZ1dG1fY2FtcGFpZ249MjAyMDAzMzBfRU5fQ09NX1JFR0lTVFJBVElPTiZ1dG1fY29udGVudD1Cb2R5JnV0bV90ZXJtPUNUQVcDc3BjQgoAAC_JgV6KRz5mUh9lbHNoYWlraHRlc3RlbWFpbHMrMjBAZ21haWwuY29tWAQAAAAB" style="font-size:14px;color:#ffffff;text-decoration:none;border-radius:2px;padding:12px 0 12px 0;display:inline-block;border-top:1px solid #499df3;border:none;font-weight:bold;min-width:190px;text-align:center;background:#1dac08"
↵ target="_blank">Confirm email</a>
thanks in advance for ur reply & help , Thank you

if you need to click on href try this
cy.get('[href*="post.spmailtechnol.com"]').click()
or
cy.get('[target="_blank"]').click()

If you are getting a raw body response (a string) you cannot use the cypress method unless you convert this strings into a DOM object so you have to get the link in this way if you have an email body as string:
const links = body.split("href=http://my.url.com");
var activation_link = links[0].match(/\bhttp?:\/\/\S+/);
activation_link= activation_link[0].replace('"','')
cy.visit(activation_link)

Related

How to send email to outlook without backend

I have a simple React application and I would like to create a form that sends an email to a specific Outlook adress without having to add my own backend.
I first looked at email.js, a library that works fine for Gmail but not for Outlook in my case. When I try to set up the correct Email, I get:
412Hotmail: Invalid login: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information. [MW4PR04CA0143.namprd04.prod.outlook.com]
This leads into a maze of powershell commands that, for reasons that are hard to summarize, were very difficult to follow through and actually make it work.
I then tried using https://www.smtpjs.com/, but I can't make it work with React. The following code:
Email.send({
Host : "smtp.yourisp.com",
Username : "username",
Password : "password",
To : 'email#email.com',
From : "you#isp.com",
Subject : "This is the subject",
Body : "And this is the body"
}).then(
message => alert(message)
);
gives the error that "Email is not defined", it doesn't matter where I insert my script tag, in my component or in index.html. I also tried
const script = document.createElement("script");
script.src = "https://smtpjs.com/v3/smtp.js"
inside the component, still does not work.
The only solution that actually works so far is https://formspree.io/, but it is a sub-par solution where the sender is redirected to a Formspree page.
I have a very vague understanding of SMTP, so perhaps I am making some rookie mistake with smtp.js.
Grateful for any help.

Meteor sendVerificationEmail

I'm currently working on revising the registration procedure of our recruitment ATS, made with AngularJS and Meteor, and I need to verify the new user's email during the registration procedure.
The logic would go as followed:
1- User fills in a form on the 'get-started' page and when clicking on 'sumbit', the ATS sends a verification email(I'll be using 'sendVerificationEmail' from Meteor)
2- After the user clicks on the link from the email, they'll get redirected to the 'register' page where additional information is required and the registration procedure is concluded.
As mentioned above, I'm planning to use 'sendVerificationEmail' to verify the user but I also want to use it to send back the userID.
From what I read on the Meteor API, I can pass extra data to the token with 'extraTokenData'
Accounts.sendVerificationEmail(userId, [email], [extraTokenData])
Now how do I declare the 'extraTokenData' object?
Could I do it like this: Accounts.sendVerificationEmail(userId, "", { _id: userId })
And how do I retrieve the 'userId' with 'Accounts.onEmailVerificationLink'?
your help will be greatly appreciated.
The email and the extra tokens are optionals, but if you want to send them send it as a string.
If you want to send the extra token but no emails you can try using Accounts.sendVerificationEmail(userId, undefined, "extra token") or if it doesn't work you can request the user's deatil user Meteor.user(). then call user.emails[0].address.
To retrieve information you have to get user by token and all data are there on user document under services.password.reset field. Look here how Accounts.generateResetToken is implemented https://github.com/meteor/meteor/blob/1e7e56eec8414093cd0c1c70750b894069fc972a/packages/accounts-password/password_server.js#L609.

How to set the Access-Token for the password reset in LoopBack with the AngularJs SDK

My Project is based on the
Loopback Getting Started Tutorial 2
I use the AngularJs SDK on the Client-Side and I want to implement the "Password-Reset"-Function.
First there is the /reset-password view, where you can enter your email address and ask for another password.
Then you get a link send per email that directs you to /set-new-password/{{accessToken}}/{{userId}}
On this view, the user enters the password and submit it. Afterwards it should find the User by Id and update its password.
But for User.findById and User.updateById I need the access-token in the Request-Header.
"Normally" the Request-Header always contains the access-token after the login. But since it's a password-reset, I'm not logged in.
I can access the access-token via $stateparams, but how can I set it in the Request-Header,so I can still use the AngularJs-SDK?
(I hope everything is clear. English is not my native language)
Edit: I have found someone with nearly the same question here. The not accepted answer works for me now.
EditEdit: Doesn't work always.. Sometimes it doesn't change the "authorization"-parameter in the Header. Can't figure out why
The solution with the LoopBack AngularJs SDK
In your angularJs controller
.controller(function (UserAccount, $location, LoopBackAuth, $scope) {
var params = $location.search();
var access_token = params.access_token;
$scope.reset = function(inputs) {
LoopBackAuth.setUser(access_token);
UserAccount.setPassword({ newPassword: inputs.newPassword });
}
})
You need to implement error control and ideally check the password twice before sending.

Quickbooks Authorization error

i have got Access token from "https://oauth.intuit.com/oauth/v1/get_request_token" using rest api in apex. when i pass the response to the authorizaiton url as shown below
https://appcenter.intuit.com/Connect/Begin?oauth_token_secret=xEtlEPu7ljKAeWRYM6pZwY02e8ewZcZ2txR1xpix&oauth_callback_confirmed=true&oauth_token=qyprdc5t2G9j8TcR8AW1123BCD3iy4M0PSBwsk84Rl8WhmCa
i get this error
Oops! An error has occurred.
Please close this window and try again.
Error Code: no_such_database
Message: Application not found by appToken
Any kind of help will be much appriciable
I am not sure if you figured it out but the URL for authorization actually seems different from documentation :
https://appcenter.intuit.com/Account/DataSharing/Authorize?oauth_token=YYYY
I used this url for authorization and it worked.
Instead of old user authorization link (https://appcenter.intuit.com/Connect/Begin ) use the new link (https://appcenter.intuit.com/Account/DataSharing/Authorize)
After generating the request token and secret , redirect to the new link. This will lead to the user authorization pages. Once authorized it will redirect back to our callback url.
Code Example :
$userAuthUrl = "https://appcenter.intuit.com/Account/DataSharing/Authorize";
$signedUrl = "{$userAuthUrl}?oauth_callback={$callBackUrl}&oauth_consumer_key={$consumerKey}&oauth_nonce={$nonce_random}&oauth_signature_method=HMAC-SHA1&oauth_timestamp={$timestamp}&oauth_token={$reqToken}&oauth_version=1.0&oauth_signature={$signature}";
header("Location:$signedUrl");
Authorized URL is not correct.
It should be like -
https://appcenter.intuit.com/connect/begin?oauth_token=qyprdsGhfVztCxWPDIXbPYjVybkwxNAvUdNNaiaTabcde
Here oauth_token is actually request_token (not request_secret) which you get as part of the first call OAuth1.0a flow.
ie. https://oauth.intuit.com/oauth/v1/get_request_token
Please refer this sample Java code which shows all the 3 steps required to generate accessToken and accessSecret (OAuth1.0a).
https://gist.github.com/manas-mukh/b6450bb28506e1302463

PUT/GET with Payload using Restangular

I am using Restangular in one of my works
The server guys have give me the following calls which i need to integrate on the AngularJS client
PUT api/partners/password – RequestPayload[{password,confirmpassword}]
partner id is being sent in the header
GET api/partners/password/forgot/ - Request Payload [{emailaddress}]
partner id is being sent in the header
The javascript code that I have written to call these services is as follow
Restangular.all('Partners').one('Password').put(params); - sends params as query string
Restangular.all('Partners').one('Password').one('Forgot').get(params); - sends object in the url
I have tried other ways but it simply doesn't make the correct call.
Help me out guys!
So, for point #1. it puts the object at hand, not another object. So you have 2 options:
Option 1
var passReq = Restangular.all('Partners').one('Password');
passReq.confirmPassword = ....
passReq.put(); // confirmPassword and the params of the object will be sent
Option 2 is
var passReq = Restangular.all('Partners').one('Password').customPUT(obj);
For Point #2, you cannot send a request body (payload) in the GET unfortunately.

Resources