Translate from C# to JS

Please translate from C# to JavaScript.
Thanks.

    private void SendEmaill()
    {
    // Create a System.Net.Mail.MailMessage object
    MailMessage message = new MailMessage();
     
    // Add a recipient
    message.To.Add("curtisgmurray@gmail.com");
     
    // Add a message subject
    message.Subject = "Email message from Curtis sent by Unity";
     
    // Add a message body
    message.Body = "Test email";
     
    // Create a System.Net.Mail.MailAddress object and set the sender email address and display name.
    message.From = new MailAddress("curtisgmurray@gmail.com", "Curtis in Unity");
     
    // Create a System.Net.Mail.SmtpClient object and set the SMTP host and port number
    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
     
     
    //smtp.SendAsync(message, "Testing, from Curtis");
     
     
    // Create a System.Net.NetworkCredential object and set the username and password required by your SMTP account
    smtp.Credentials = new System.Net.NetworkCredential("curtisgmurray@gmail.com", "JuicyFruit");
     
    //Enable Secure Socket Layer (SSL) for connection encryption
    smtp.EnableSsl = true;
     
    // Do not send the DefaultCredentials with requests
    smtp.UseDefaultCredentials = false;
     
    // Send the message
    smtp.Send(message);
    }

Try this:

private function SendEmaill() 
    { 
    // Create a System.Net.Mail.MailMessage object 
    var message = new MailMessage();
      
    // Add a recipient 
    message.To.Add("curtisgmurray@gmail.com"); 
      
    // Add a message subject 
    message.Subject = "Email message from Curtis sent by Unity"; 
      
    // Add a message body 
    message.Body = "Test email"; 
      
    // Create a System.Net.Mail.MailAddress object and set the sender email address and display name. 
    message.From = new MailAddress("curtisgmurray@gmail.com", "Curtis in Unity"); 
      
    // Create a System.Net.Mail.SmtpClient object and set the SMTP host and port number 
    var smtp = new SmtpClient("smtp.gmail.com", 587); 
      
      
    //smtp.SendAsync(message, "Testing, from Curtis"); 
      
      
    // Create a System.Net.NetworkCredential object and set the username and password required by your SMTP account 
    smtp.Credentials = new System.Net.NetworkCredential("curtisgmurray@gmail.com", "JuicyFruit"); 
      
    //Enable Secure Socket Layer (SSL) for connection encryption 
    smtp.EnableSsl = true; 
      
    // Do not send the DefaultCredentials with requests 
    smtp.UseDefaultCredentials = false; 
      
    // Send the message 
    smtp.Send(message); 
    }

thanks for reply, but I have errors.

Oryginal script is from,

i’m teaching it but i donit know whai is wrong.

Pleas help.

BCE0005: Unknown identifier: ‘MailMessage’.

(Filename: Assets/mail.js Line: 4)

Assets/zamow.js(16,24): BCE0005: Unknown identifier: ‘MailAddress’.

(Filename: Assets/mail.js Line: 16)

Assets/zamow.js(19,20): BCE0005: Unknown identifier: ‘SmtpClient’.

(Filename: Assets/mail.js Line: 19)

I’m working with Unity3.5 to Flash

maybe this from C# I need to JS?

using System.Net.Mail;
using System.Net;

Yep

import System.Net.Mail;
import System.Net;

Errors in line 1 and line 2:
(1,6): UCE0001: ‘;’ expected. Insert a semicolon at the end.

using System.Net.Mail;
using System.Net;


private function SendEmaill() 
    { 
    // Create a System.Net.Mail.MailMessage object 
    var message = new MailMessage();
      
    // Add a recipient 
    message.To.Add("curtisgmurray@gmail.com"); 
      
    // Add a message subject 
    message.Subject = "Email message from Curtis sent by Unity"; 
      
    // Add a message body 
    message.Body = "Test email"; 
      
    // Create a System.Net.Mail.MailAddress object and set the sender email address and display name. 
    message.From = new MailAddress("curtisgmurray@gmail.com", "Curtis in Unity"); 
      
    // Create a System.Net.Mail.SmtpClient object and set the SMTP host and port number 
    var smtp = new SmtpClient("smtp.gmail.com", 587); 
      
      
    //smtp.SendAsync(message, "Testing, from Curtis"); 
      
      
    // Create a System.Net.NetworkCredential object and set the username and password required by your SMTP account 
    smtp.Credentials = new System.Net.NetworkCredential("curtisgmurray@gmail.com", "JuicyFruit"); 
      
    //Enable Secure Socket Layer (SSL) for connection encryption 
    smtp.EnableSsl = true; 
      
    // Do not send the DefaultCredentials with requests 
    smtp.UseDefaultCredentials = false; 
      
    // Send the message 
    smtp.Send(message); 
    }

C#

using System........

UnityScript:

import System.......

Also, if the C# class where this method is located doesn’t derive from MonoBehaviour, you may need to add the class declaration to your script as well:

import System.Net.Mail; 
import System.Net; 

class MyClassNameHere
{
    private function SendEmaill() 
    { 
        // Create a System.Net.Mail.MailMessage object 
        var message = new MailMessage();
          
        // Add a recipient 
        message.To.Add("curtisgmurray@gmail.com"); 
          
        // Add a message subject 
        message.Subject = "Email message from Curtis sent by Unity"; 
          
        // Add a message body 
        message.Body = "Test email"; 
          
        // Create a System.Net.Mail.MailAddress object and set the sender email address and display name. 
        message.From = new MailAddress("curtisgmurray@gmail.com", "Curtis in Unity"); 
          
        // Create a System.Net.Mail.SmtpClient object and set the SMTP host and port number 
        var smtp = new SmtpClient("smtp.gmail.com", 587); 
          
          
        //smtp.SendAsync(message, "Testing, from Curtis"); 
          
          
        // Create a System.Net.NetworkCredential object and set the username and password required by your SMTP account 
        smtp.Credentials = new System.Net.NetworkCredential("curtisgmurray@gmail.com", "JuicyFruit"); 
          
        //Enable Secure Socket Layer (SSL) for connection encryption 
        smtp.EnableSsl = true; 
          
        // Do not send the DefaultCredentials with requests 
        smtp.UseDefaultCredentials = false; 
          
        // Send the message 
        smtp.Send(message); 
    }

    // ...
    // Other methods here
    // ...

}

thanks for reply, it works!

After send email i have errors.
Bad SSL email configuration or bad script?

InvalidOperationException: SSL authentication error: RemoteCertificateNotAvailable, RemoteCertificateChainErrors
System.Net.Mail.SmtpClient.m__4 (System.Object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors)
System.Net.Security.SslStream+c__AnonStorey7.<>m__A (System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Int32[ ] certErrors)
Mono.Security.Protocol.Tls.SslClientStream.OnRemoteCertificateValidation (System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Int32[ ] errors)
Mono.Security.Protocol.Tls.SslStreamBase.RaiseRemoteCertificateValidation (System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Int32[ ] errors)
Mono.Security.Protocol.Tls.SslClientStream.RaiseServerCertificateValidation (System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Int32[ ] certificateErrors)
Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates)
Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 ()
Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process ()
(wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process ()
Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg)
Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult)
Rethrow as IOException: The authentication or decryption has failed.
Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult)
Rethrow as SmtpException: Message could not be sent.
System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message)
Menu.SendEmaill () (at Assets/Menu.js:143)
Menu.OnGUI () (at Assets/Menu.js:96)

The configuration, I guess.