Skip to content

Instantly share code, notes, and snippets.

@cchitsiang
Created October 24, 2013 07:33
Show Gist options
  • Save cchitsiang/7132804 to your computer and use it in GitHub Desktop.
Save cchitsiang/7132804 to your computer and use it in GitHub Desktop.
SendEmail Custom Activity
using System;
using System.Activities;
using System.ComponentModel;
namespace MyActivityLibrary {
public sealed class SendEmailActivity : CodeActivity {
public InArgument<string> to { get; set; }
public InArgument<string> subject { get; set; }
public InArgument<string> body { get; set; }
private string from = "*****@****.com";
private string host = "smtp.*****.com";
private string userName = "******";
private string password = "*****";
public OutArgument<string> result { get; set; }
protected override void Execute(CodeActivityContext context) {
var mailMessage = new System.Net.Mail.MailMessage();
mailMessage.To.Add(to.Get(context).ToString());
mailMessage.Subject = subject.Get(context).ToString();
mailMessage.Body = body.Get(context);
mailMessage.From = new System.Net.Mail.MailAddress(from);
var smtp = new System.Net.Mail.SmtpClient();
smtp.Host = host;
smtp.Credentials = new System.Net.NetworkCredential(userName, password);
smtp.EnableSsl = true;
smtp.Send(mailMessage);
result.Set(context, "ok");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment