I want to access the string parameter declared in a method from another method.
i.e., I made a string parameter called string survey in SaveLocal method. Now I want this to be accessed by the SendEmail method so I can get the string survey as the mail body (mail.Body).
//code
void SaveLocal(string survey, int id)
{
//save to disk
string fileName = “results” + id.ToString(“D4”);
print("Filename: " + fileName);
Debug.Log(Application.persistentDataPath);
string filePath = Application.persistentDataPath + "/"+fileName + ".json";
//string path = Application.persistentDataPath;
byte[] JsonStringBytes = Encoding.UTF8.GetBytes(survey);
File.WriteAllBytes(filePath, JsonStringBytes);
InfoText.text += "
" + MainMenuBehaviour.CurrentDictionary.GetKeyValue(“saved_locally”, false);
}
//code 2
public void SendEmail() { MailMessage mail = new MailMessage();
mail.From = new MailAddress(“sender@gmail.com”);
mail.To.Add(“reciever1@gmail.com”);
mail.To.Add(“reciever2@gmail.com”);
mail.To.Add(“reciever3@gmail.com”);
mail.Subject = “Test Mail”;
mail.Body = “This is for testing SMTP mail from GMAIL”; //MAIL BODY
SmtpClient smtpServer = new SmtpClient(“smtp.gmail.com”);
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(“sender@gmail.com”, “senderpassword”) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
Debug.Log(“success”);