I am trying to send email using google API in asp.net c# and getting Error 400 redirect_uri_mismatch
below is my code:
public void sendemail()
{
static string[] Scopes = { GmailService.Scope.GmailSend};
static string ApplicationName = "GmailAPIWeb";
string CLIENT_ID = "***********************";
string CLIENT_SECRET = "************";
var secrets = new ClientSecrets
{
ClientId = CLIENT_ID,
ClientSecret = CLIENT_SECRET
};
//Error will throw from here...
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
secrets,
Scopes, "user",
CancellationToken.None, null
//new FileDataStore(credPath, true)
).Result;
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
//Create Message`enter code here`
MailMessage mail = new MailMessage();
mail.Subject = "Subject!";
mail.Body = "This is <b><i>body</i></b> of message";
mail.From = new MailAddress("jayesh@gmail.com");
mail.IsBodyHtml = true;
mail.To.Add(new MailAddress("jayesh@gmail.com"));
MimeKit.MimeMessage mimeMessage =
MimeKit.MimeMessage.CreateFromMailMessage(mail);
var gmailMessage = new Google.Apis.Gmail.v1.Data.Message
{
Raw = Encode(mimeMessage.ToString())
};
//Send Email
var result = service.Users.Messages.Send(gmailMessage, "me/OR UserId/EmailAddress").Execute();
}
The redirect URI in the request, http://127.0.0.1:55878/authorize/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}
I want send email using google api using c#.