2014-01-26 2 views
0

Im 스크린 샷을 찍어 저장하고 있지만 읽는 법을 모르며 Gmail로 이메일에 첨부하여 보내주십시오. 지금까지 내가, 당신이 이미 첨부 파일을 추가 할 볼 수스크린 샷을 이메일 첨부 파일로 보내십시오.

// We should only read the screen after all rendering is complete 
yield return new WaitForEndOfFrame(); 

// Create a texture the size of the screen, RGB24 format 
int width = Screen.width; 
int height = Screen.height; 
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); 
// Read screen contents into the texture 
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); 
tex.Apply(); 

// Encode texture into PNG 
byte[] bytes = tex.EncodeToPNG(); 

// save our test image (could also upload to WWW) 
File.WriteAllBytes(Application.dataPath + "/../test-" + count + ".png", bytes); 
count++; 

DestroyObject(tex); 

Debug.Log(Application.dataPath + "/../test-" + count + ".png"); 



MailMessage mail = new MailMessage(); 

mail.From = new MailAddress("[email protected]"); 
mail.To.Add("[email protected]"); 
mail.Subject = "Test"; 
mail.Body = "testing class"; 
mail.Attachments.Add(new Attachment(Application.dataPath + "/../teste-" + count + ".png", 
            Application.dataPath + "/../teste-" + count + ".png", 
            "png")); 

SmtpClient smtpServer = new SmtpClient("smtp.gmail.com"); 
smtpServer.Port = 587; 
smtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "123456") as ICredentialsByHost; 
smtpServer.EnableSsl = true; 
ServicePointManager.ServerCertificateValidationCallback = 
    delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
{ 
    return true; 
}; 
smtpServer.Send(mail); 
Debug.Log("success"); 
+0

내가 볼 수있는 유일한 방법은 당신의'MailMessage'와'SmtpClient' 객체가 제대로 닫히지 확인하기 위해,'using' 블록의 내부에 있어야한다. 나는'using' 블록이 추가 될 때까지 이메일 전송이 지연되는 문제로 과거에 문제가있었습니다. –

답변

2

: 여기 내 코드의

mail.Attachments.Add(new Attachment(Application.dataPath + "/../teste-" + count + ".png", 
            Application.dataPath + "/../teste-" + count + ".png", 
            "png")); 

문제가, MIME 타입이 잘못하고 경로는 하나 다르다 당신은에 이미지를 저장하고 :

File.WriteAllBytes(Application.dataPath + "/../test-" + count + ".png", bytes); 

여기에는 teste 없다! 다음

봅니다 :

mail.Attachments.Add(new Attachment(Application.dataPath + "/../test-" + count + ".png", 
            @"image/png")); 
+0

답장을 보내 주셔서 감사합니다. 그러나 매개 변수가 잘못되었다고 생각합니다. 'System.Net.Mail.Attachment.Attachment (System.IO.Stream, string, string)'에 가장 적합한 오버로드 된 메서드가 있습니다. 잘못된 인수 – darkman

+0

좋습니다, 파일 이름과 첨부 파일 이름을 보낼 수 없습니다. 지금 확인하십시오. – MarcinJuraszek

관련 문제