Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by unity_XY9GfkpHMyaikw · May 14, 2019 at 10:36 AM · stringmethodemailmail

How to access parameter of a method (declared in the method itself) from another method?

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 += "\n\n" + 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");

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · May 14, 2019 at 11:01 AM

you cant, just declare it outside. declare the variable outside the method and just assign it inside, local vars memory get errased even if you could access method variables

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadyProductions · May 14, 2019 at 05:43 PM 0
Share

unless the parameter is passed with ref keyword

avatar image xxmariofer ShadyProductions · May 14, 2019 at 06:26 PM 0
Share

Pretty sure he is not trying to pass the reference of a var but access a local method var, and accessing a mdthod local var is not posible

avatar image Owen-Reynolds · May 14, 2019 at 08:19 PM 0
Share

I think this is one of those "How do I become a dual Iranian-American citizen?" Because they want to buy Safron and someone told them only Iranian citizens can buy it. I think they're asking how a function can compute something and tell the rest of the program about it. I think.

avatar image unity_XY9GfkpHMyaikw · May 15, 2019 at 05:04 AM 0
Share

I am storing all the answers to a questionnaire in the string survey. How do I get all the data in the string and print in the mail body so I can Email it to the recipients?

avatar image xxmariofer unity_XY9GfkpHMyaikw · May 15, 2019 at 11:54 AM 0
Share

Create a var outside the method

 private void string savedSurvey;

And inside the methof initialize it

 savedSurvey = survey;

Now you xan access saved survey from anywhere inside the class

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

110 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to send a string in mail.Body? 0 Answers

iOS + SmtpClient + PickupDirectoryLocation + attachment = über slow? 0 Answers

\n Not picked up when reading string from file's name 1 Answer

checking a bool via string 0 Answers

How to prevent to save or send a big json string? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges