事实证明,我需要添加以下内容,并重新发布我的应用程序并更新我的服务参考:
SLEmailMessage.cs:
[DataContract]
public class SLEmailMessage
{
[DataMember]
public string To { get; set; }
[DataMember]
public string From { get; set; }
[DataMember]
public string Subject { get; set; }
[DataMember]
public string Body { get; set; }
[DataMember]
public string CC { get; set; }
[DataMember]
public string Bcc { get; set; }
[DataMember]
public string Attachment { get; set; }
}
电子邮件服务.svc.cs:
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class EmailService
{
[OperationContract]
public bool SendEmail(SLEmailMessage emailMessage)
{
bool IsEmailSendSuccessful = false;
try
{
MailMessage mailMessage = new MailMessage(emailMessage.From, emailMessage.To);
mailMessage.CC.Add(emailMessage.CC);
mailMessage.Bcc.Add(emailMessage.Bcc);
var pdfMessage = new Attachment(emailMessage.Attachment);
pdfMessage.ContentDisposition.FileName="BikeCountInfo.pdf";
mailMessage.Attachments.Add(pdfMessage);
mailMessage.Subject = emailMessage.Subject;
mailMessage.Body = emailMessage.Body;
SmtpClient smtp = new SmtpClient();
smtp.Send(mailMessage);
IsEmailSendSuccessful = true;
}
catch
{
IsEmailSendSuccessful = false;
}
return IsEmailSendSuccessful;
}
// Add more operations here and mark them with [OperationContract]
}
更新服务并重新发布应用程序 - 然后添加:
MainPage.xaml.cs:
if (SelectedFeatureLayer.ID == "AllAvailableFeatureLayer" || SelectedFeatureLayer.ID == "PMAvailableLayer")
{
if (msgToPM.Length != 0 & Regex.IsMatch(msgToPM, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
SLEmailMessage PMemailMessage = new SLEmailMessage
{
To = msgToPM,
From = "email@name.org",
CC = "email@name.org",
Bcc = "email@name.org",
Attachment = "location of attachment",
Subject = "Thanks to Bike Count Volunteers",
Body = PMmsgBody
};
emailClient.SendEmailAsync(PMemailMessage);
}