I am getting (Compiler Error) "Error CS0120 An object reference is required for the non-static field, method, or property ". My code is mentioned below. Can please anyone assist me how to fix this issue.
private static Task<string> SendPasswordResetVerificationCode(string email)
{
string randomVerificationCode = new Random().Next(1000, 9999).ToString(CultureInfo.CurrentCulture);
////send verification code to given email
if (email != null)
{
SendEmail(email, randomVerificationCode);
return Task.FromResult("VerificationCode Sent");
}
return Task.FromResult("VerificationCode Sent");
}
/// <summary>
/// Sends an email for verification code
/// </summary>
/// <param name="email">email address that will receive verification code</param>
/// <param name="verificationCode">verification code</param>
private void SendEmail(string email, string verificationCode)
{
Task.Run(() =>
{
try
{
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("v@gmail.com");
mail.To.Add(email);
mail.IsBodyHtml = true;
mail.Subject = "Verification Code";
mail.Body = verificationCode;
smtpServer.Port = 587;
smtpServer.UseDefaultCredentials = false;
smtpServer.EnableSsl = true;
smtpServer.Send(mail);
mail.Dispose();
}
catch (Exception ex)
{
Utilities.Logging.LogManager.Write(ex);
}
});
}