首页 > 解决方案 > 使用依赖服务实现发送电子邮件功能

问题描述

使用依赖服务实现发送电子邮件功能。以下字段应可配置To、Cc、Bcc、Subject 和 Details

我尝试了许多示例,例如example1Example2等等。这些都没有帮助。

我可以在使用 Xam.Plugins.Messaging 的代码中做到这一点,但我需要使用 Dependency 服务来实现电子邮件服务。我不知道如何解决这个问题。有什么建议么?

标签: emailxamarindependency-injectionxamarin.forms

解决方案


API 文档包括使用cc的示例

// Alternatively use EmailBuilder fluent interface to construct more complex e-mail   with multiple recipients, bcc, attachments etc.
var email = new EmailMessageBuilder()
  .To("to.plugins@xamarin.com")
  .Cc("cc.plugins@xamarin.com")
  .Bcc(new[] { "bcc1.plugins@xamarin.com", "bcc2.plugins@xamarin.com" })
  .Subject("Xamarin Messaging Plugin")
  .Body("Well hello there from Xam.Messaging.Plugin")
  .Build();

emailMessenger.SendEmail(email);

附件

var email = new EmailMessageBuilder()
  .To("to.plugins@xamarin.com")
  .Subject("Xamarin Messaging Plugin")
  .Body("Well hello there from Xam.Messaging.Plugin")
  .WithAttachment("<path_to_picture>", "image/jpeg");
  .Build();

推荐阅读