Xamarin.Android中的图像路径

时间:2016-02-11 08:38:23

标签: c# android email xamarin.forms

我想在xamarin.android中发送邮件。我可以使用下面的代码发送文本但没有图像但是当我尝试使用图像作为徽标发送时会出现问题。我的意思是,我无法找到图像的路径。

我的发送邮件方式是:

public static void SendMail(List<string> to, List<string> cc, string subject, string body,string mfrom)
{
    string messageHeader = "Android E-Mail Testi";
    MailMessage msg = new MailMessage();
    msg.From = new MailAddress(mfrom);
    msg.To.Add(new MailAddress(to[0]));
    msg.CC.Add(new MailAddress(cc[0]));

    var inlineLogo = new LinkedResource("Drawable://logo.png");//This path is not working.
    inlineLogo.ContentId = Guid.NewGuid().ToString();

    msg.Body = string.Format(@"<img class=""img-responsive"" src=""cid:{0}"" style=""width:25%; float:left""/>
                              <br/><br/><h3>" + messageHeader + @"</h3>" + body, inlineLogo.ContentId);

    var view = AlternateView.CreateAlternateViewFromString(msg.Body, null, "text/html");
    view.LinkedResources.Add(inlineLogo);
    msg.AlternateViews.Add(view);

    msg.IsBodyHtml = true;
    msg.Subject = subject;
    msg.SubjectEncoding = Encoding.UTF8;

    SmtpClient smtpClient = new SmtpClient("xx.xxx.x.xxx");
    msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;


    List<MemoryStream> mStreams = null;

    msg.BodyEncoding = Encoding.Unicode;
    smtpClient.Send(msg);

    if (mStreams != null)
        foreach (MemoryStream mStream in mStreams)
            mStream.Close();
}

我可以在asp.net中使用此代码发送邮件。只有文件路径不同。我这样使用它,它适用于Web开发:

var inlineLogo = new LinkedResource(HostingEnvironment.MapPath("~/images/logo.png"));

我应该在xamarin的image(logo.png)路径中使用哪种方法?

var inlineLogo = new LinkedResource(???);

我不知道真正的路径。如何在Resources文件夹的drawable文件夹中找到图像的路径?

目录是:

enter image description here

1 个答案:

答案 0 :(得分:2)

也许它会对你有所帮助。我用相同的文件夹Resources / drawable以这样的方式创建了带有图标的ToolbarItem:

GA.LogItem (transID, itemName, sku, affiliation, revenue, 1); 
GA.LogTransaction (transID, affiliation, revenue, 0, 0, currencyCode);
GA.LogEvent ("transaction", "triggered", "", 0);