我正在尝试从网络服务器(pdf 文件)下载文件并保存到我的 sd 卡中,或者直接将此文件附加到电子邮件并在此之后发送电子邮件。
我的应用程序需要向一些学生发送电子邮件,其中包含一些 pdf 格式的信息,我已经发送了带有主题和竞争的电子邮件,但由于我使用的是 unity + android,我无法下载和/或阅读 pdf 文件。
我正在尝试使用 WWW 类但不工作
if(loadInfo.getPantallaActual().Equals("pantallaInicio"))
{
Email objEmail = LoadCarreras.objXML.objCarrera.GetEmail();
string to = "to@hotmail.com";
string from = "from@gmail.com";
string subject = objEmail.GetAsunto();
string body = objEmail.GetCuerpo();
string urlAttachment = objEmail.GetContenido_url();
StartCoroutine(descarga(urlAttachment));
archivo = Path.GetFileName(urlAttachment);
File.CreateText(Application.persistentDataPath + "/"+archivo);
Debug.Log(" urlAttachment "+urlAttachment);
Debug.Log(" archivo "+archivo);
Debug.Log(" persistentDataPath "+Application.persistentDataPath + "/"+archivo);
message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = (ICredentialsByHost) new System.Net.NetworkCredential("from@gmail.com", "pasw.");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Timeout = 10000;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
try {
client.Send(message);
}
catch (System.Exception ex) {
Debug.Log("Exception caught in CreateTestMessage1(): "+ex.ToString() );
}
public IEnumerator descarga(string url){
descargaA = new WWW(url);
mandarEmail = true;
yield return descargaA;
}
void Update () {
if(mandarEmail)
{
if(descargaA.isDone && cambiar){
message.Attachments.Add (new Attachment(Application.persistentDataPath + "/"+"file.pdf"));
cambiar = false;
}
}
}