I have created a simple app with third party email sending api implementation to get email through contact form. When I am running the app on my local host or on my github page, I am getting this error:
Access to XMLHttpRequest at 'https://api.mailjet.com/v3.1/send' from origin 'https://myrepo.github.io' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
What is the solution for that issue. Obviously I can't apply any solution in API end, all I have to do is from my angular code. Here is what I have implemented in my http post request
sendMail(): Observable<any>{
let API_URL='https://api.mailjet.com/v3.1/send';
let data={
"Messages":[
{
"From": {
"Email": "myemail@gmail.com",
"Name": "My Name"
},
"To": [
{
"Email": "myemail@gmail.com",
"Name": "My Name"
}
],
"Subject": "My first Mailjet email",
"TextPart": "Greetings from Mailjet.",
"HTMLPart": "<h3>Dear passenger 1, welcome to <a href=https://www.mailjet.com/>Mailjet</a>!</h3><br />May the delivery force be with you!",
"CustomID": "AppGettingStartedTest"
}
]
};
console.log('sending email....')
console.log(data);
this.httpClient.post<any>(API_URL,data,{
headers: new HttpHeaders({
'Content-Type':'application/json',
'Authorization':'Basic VGIzOTIsasdasdasdasdasdrewetwfdsfasdasMjI0NWUVcDFGA='
})
}).subscribe(res=>{
console.log(res);
},err=>{
console.log(err);
});
return null;//ignoring this for now.
}