电子邮件不发送统一的android?

时间:2017-04-11 02:24:15

标签: android email unity3d

我看了很多来源和问题,但我仍然不清楚这个通过统一发送电子邮件的代码如何在android构建中不起作用。它在windows build中工作正常,但在android中不起作用。有人能帮我吗。这是代码 -

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
public class EmailUnity
{

public static string SenderEmail;
public static string SenderPassword;
public static string SmtpClient;
public static int SmtpPort;

public static void SendEmail(string to, string subject, string body, bool isHtml, string[] attachmentPaths,
    Action<object, AsyncCompletedEventArgs> callback = null)
{
    try
    {
        SmtpClient emailServer = new SmtpClient(SmtpClient, SmtpPort);
        emailServer.EnableSsl = true;
        emailServer.Credentials = (ICredentialsByHost) new NetworkCredential(SenderEmail, SenderPassword);

        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

        MailMessage message = new MailMessage(SenderEmail, to);
        message.Subject = subject;
        message.Body = body;
        message.IsBodyHtml = isHtml;

        foreach (string path in attachmentPaths)
        {
            if (!string.IsNullOrEmpty(path) && File.Exists(path))
            {
                message.Attachments.Add(new Attachment(path));
            }
        }
        if (callback == null)
        {
            callback = SampleCallback;
        }
        emailServer.SendCompleted += new SendCompletedEventHandler(callback);
        emailServer.SendAsync(message, "");

        Debug.Log("Email sending");
    }
    catch (Exception ex)
    {
        Debug.Log("Error: " + ex.Message);
        callback("", new AsyncCompletedEventArgs(ex, true, "Exception occured"));
    }
}

private static void SampleCallback(object sender, AsyncCompletedEventArgs e)
{
    if (e.Cancelled || e.Error != null)
    {
        Debug.Log("Error: " + e.Error.Message);
    }
    else
    {
        Debug.Log("Email sent");
    }
}
}

1 个答案:

答案 0 :(得分:1)

如果Elasticsearch ERROR: 2017-04-11T04:40:01Z Error: Request error, retrying POST http://localhost:9200/reports/report/_search?size=5000000 => connect ECONNREFUSED 127.0.0.1:9200 at Log.error (/home/kartik/Documents/Project/Validus/validus_reports_server/node_modules/elasticsearch/src/lib/log.js:225:56) at checkRespForFailure (/home/kartik/Documents/Project/Validus/validus_reports_server/node_modules/elasticsearch/src/lib/transport.js:240:18) at HttpConnector.<anonymous> (/home/kartik/Documents/Project/Validus/validus_reports_server/node_modules/elasticsearch/src/lib/connectors/http.js:162:7) at ClientRequest.wrapper (/home/kartik/Documents/Project/Validus/validus_reports_server/node_modules/lodash/lodash.js:4968:19) at emitOne (events.js:77:13) at ClientRequest.emit (events.js:169:7) at Socket.socketErrorListener (_http_client.js:258:9) at emitOne (events.js:77:13) at Socket.emit (events.js:169:7) at emitErrorNT (net.js:1256:8) { [Error: No Living connections] message: 'No Living connections', body: undefined, status: undefined } 无法在Android上运行,可以尝试以下操作。

转到文件 - &gt; 构建设置... - &gt;选择 Android 。现在,点击播放器设置

1 。在 Internet Access 上,将其从自动更改为需要

2 。确保API兼容级别设置为 .NET 2.0 而不是 .NET 2.0子集

3 。确保剥离级别设置为已禁用

4 。转到播放器设置 - &gt; Android 并将 Internet访问自动更改为需要