Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Mail;
- using UnityEngine;
- using System.Threading;
- public static class UnityMail {
- private const string username = "seuemail@email.com";
- private const string password = "suaSenha123";
- private const string client = "smtp.gmail.com";
- private const int port = 587;
- /*
- Usage:
- UnityMail.Send("algumfdp@email.com", "Titulo", "Texto");
- UnityMail.SendAsync("algumfdp@email.com", "Titulo", "Texto");
- */
- public static bool Send(string receiver, string subject, string body) {
- try {
- using(var mail = new MailMessage()) {
- mail.From = new MailAddress(username);
- mail.To.Add(receiver);
- mail.Subject = subject;
- mail.Body = body;
- var server = new SmtpClient(client);
- server.Port = port;
- server.Credentials = new NetworkCredential(username, password) as ICredentialsByHost;
- server.EnableSsl = true;
- ServicePointManager.ServerCertificateValidationCallback += (sender, certificade, chain, sslErrors) => { return true; };
- server.Send(mail);
- Debug.Log("Send email to " + receiver);
- return true;
- }
- }
- catch(Exception ex) {
- Debug.LogWarning(ex);
- Debug.LogWarning("Error sending email");
- return false;
- }
- }
- public bool ready = true;
- public static void SendAsync(string receiver, string subject, string body) {
- new Thread(() => {
- ready = false;
- try{
- Send(receiver, subject, body);
- }
- finally{
- ready = true;
- }}).Start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement