Created
October 24, 2013 07:33
-
-
Save cchitsiang/7132804 to your computer and use it in GitHub Desktop.
SendEmail Custom Activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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