I also did send mail by custom workflow.
I have use below methods.
both method working fine.
First Method
private bool sendEmail(SPWeb web, string from, string to, string cc, string bcc, string subject, string body)
{
try
{
StringDictionary headers = new StringDictionary();
headers.Add("to", to);
headers.Add("cc", cc);
headers.Add("bcc", bcc);
headers.Add("from", from);
headers.Add("subject", subject);
headers.Add("content-type", "text/html");
bool flag = SPUtility.SendEmail(web, headers, body);
if (flag)
return true;
}
catch
{
return false;
}
return false;
}
}
Second Method
public static bool SendMail(string Subject, string Body, bool IsBodyHtml, string From, string To, string Cc, string Bcc)
{
bool mailSent = false;
try
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = SPContext.Current.Site.WebApplication.OutboundMailServiceInstance.Server.Address;
MailMessage mailMessage = new MailMessage(From, To, Subject, Body);
if (!String.IsNullOrEmpty(Cc))
{
MailAddress CCAddress = new MailAddress(Cc);
mailMessage.CC.Add(CCAddress);
}
if (!String.IsNullOrEmpty(Bcc))
{
MailAddress BCCAddress = new MailAddress(Bcc);
mailMessage.Bcc.Add(BCCAddress);
}
mailMessage.IsBodyHtml = IsBodyHtml;
smtpClient.Send(mailMessage);
mailSent = true;
}
catch (Exception ex)
{
return mailSent;
}
return mailSent;
}