Send

    技术2025-03-24  11

    bool SendMail(string userName, string passWord, string from, string to, string subject, string body) { System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587); smtp.Credentials = new NetworkCredential(userName, passWord); smtp.EnableSsl = true; System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(new System.Net.Mail.MailAddress(from), new System.Net.Mail.MailAddress(to)); message.BodyEncoding = System.Text.Encoding.UTF8;//可以设置内容的编码方式 message.SubjectEncoding = System.Text.Encoding.UTF8; message.Body = body;//邮件内容 message.Subject = subject;//邮件标题 try { smtp.Send(message); return true; } catch { return false; } }

    最新回复(0)