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);
}
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);
}
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);
}
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
// ...
}