Skip to content

Instantly share code, notes, and snippets.

@MuhammadFaizanKhan
Last active December 6, 2019 07:03
Show Gist options
  • Select an option

  • Save MuhammadFaizanKhan/e67b9af2ed405ebd7224defe158e91f5 to your computer and use it in GitHub Desktop.

Select an option

Save MuhammadFaizanKhan/e67b9af2ed405ebd7224defe158e91f5 to your computer and use it in GitHub Desktop.

Revisions

  1. MuhammadFaizanKhan renamed this gist Dec 6, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. MuhammadFaizanKhan created this gist Dec 6, 2019.
    41 changes: 41 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    using System.Net;
    using System.Net.Mail;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    using UnityEngine;

    public class SendEmail : MonoBehaviour
    {
    public string fromEmail = "yourGmailAccountFromWhereYouWantToSendEmail";
    public string toEmail = "WhomYouWantToSendEmail";
    public string subject = "SubjectName";
    public string body = "Body of the email";
    public string password = "YourGmailAccountPassword";
    // Start is called before the first frame update
    void Start()
    {
    EmailSending();
    }

    // Update is called once per frame
    void EmailSending()
    {

    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(fromEmail);
    mail.To.Add(toEmail);
    mail.Subject = subject;
    mail.Body = body;
    // you can use others too.
    SmtpClient smtpServer = new SmtpClient("smtp.gmail.com",587);
    //smtpServer.Port = 587;
    smtpServer.Credentials = new System.Net.NetworkCredential(fromEmail, password) as ICredentialsByHost;
    smtpServer.EnableSsl = true;
    ServicePointManager.ServerCertificateValidationCallback =
    delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    { return true; };
    smtpServer.Send(mail);

    }

    }