How to use Unity3d to send messages with attachments

Source: Internet
Author: User
Tags mailmessage smtpclient

Take Gmail for example.
Tap the Capture button on the screen to get the current screen, and click the Send button to send the previous message as an attachment.

usingUnityengine;usingSystem.Collections;usingSystem;usingSystem.Net;usingSystem.Net.Mail;usingSystem.Net.Security;usingSystem.Security.Cryptography.X509Certificates; Public classTrydemo:monobehaviour {//Use this for initialization    voidStart () {}//Update is called once per frame    voidUpdate () {}voidOngui () {if(GUI. Button (NewRect (0, -, -, +),"Capture") {Debug.Log ("Capture screenshot"); Application.capturescreenshot ("Screen.png"); }        if(GUI. Button (NewRect (0,0, -, +),"Send") ) {SendEmail (); }    }     Private voidSendEmail () {MailMessage mail=NewMailMessage (); Mail. from=NewMailAddress ("[email protected]"); Mail. To.add ("[email protected]"); Mail. Subject="Test Mail"; Mail. Body="testing SMTP mail from GMAIL"; Mail. Attachments.Add (NewAttachment ("Screen.png")); SmtpClient SmtpServer=NewSmtpClient ("smtp.gmail.com"); Smtpserver.port=587; Smtpserver.credentials=NewSystem.Net.NetworkCredential ("[email protected]","YourPassword") asIcredentialsbyhost; Smtpserver.enablessl=true; Servicepointmanager.servercertificatevalidationcallback=Delegate(Objects, x509certificate certificate, X509chain chain, sslpolicyerrors sslpolicyerrors) { return true; };        Smtpserver.send (mail); Debug.Log ("Success"); }}

①application.registerlogcallback (Ondebugcallbackhandler); You can add a callback function to debug print, listen for each print, and use this to determine if there is an error log and react.
② Basic Send Error log method is sent by mail, you can use C # script in unity to send mail, the specific method mentioned above, or through Process.Start ("Name.exe") to invoke external programs to send log mail, Specific operation can be Baidu C program to send mail, there are many examples.
③ sending mail logs in C # scripts is easier to implement, and C # provides the encapsulation of mail-sending capabilities. You can also use Application.capturescreenshot ("filename") to save the program for sending, providing errors.

Original link

How to use Unity3d to send messages with attachments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.