I have a razor component in my Blazor project where when user click a button it will trigger email

The OnClick function Email will send email, through the below code
async Task Email(string originalpiv, string docno, string cuscode, string cusname, string docdate)
{
CModule.SendMail("[email protected]", "[email protected]", "", "HI", "HI BRO");
}
The CModule.SendMail is method where the email from,to,subj,body will be passed, below code
public static bool SendMail(string from, string to, string cc, string subject, string body)
{
bool rst = false;
MailMessage Msg = new MailMessage();
try
{
SmtpClient smtp = new SmtpClient("mail.gmail.com", 587);
string[] toeml = to.Split(new Char[] { ';', ',' });
foreach (string tmp in toeml)
{
if (tmp.Trim() != "") Msg.To.Add(tmp.Trim());
}
string[] cceml = cc.Split(new Char[] { ';', ',' });
foreach (string tmp in cceml)
{
if (tmp.Trim() != "") Msg.CC.Add(tmp.Trim());
}
Msg.From = new MailAddress(from.Trim());
Msg.Subject = subject;
Msg.Body = body;
Msg.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "880215");
smtp.Send(Msg);
rst = true;
}
catch (Exception ex)
{
}
finally
{
Msg.Dispose();
}
return rst;
}
These are the code that i have tried, but the email is not sending out, not sure of why, any idea?