I have an event receiver which get fired when a new discussion board item is added. inside the event receiver i am sending email to certain users group, as follow:-
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
string fromField = "Sharepoint@ourcompany.net";
using (MailMessage myMailMessage = new MailMessage())
{
foreach (SPUser pp in properties.Web.SiteGroups.GetByID(int.Parse(groupid)).Users)
{
if (pp.Email != null && !string.IsNullOrEmpty(pp.Email))
myMailMessage.To.Add(new MailAddress(pp.Email));
}
System.Text.StringBuilder mailBody = new System.Text.StringBuilder();
mailBody.AppendLine("<span style='font-family:Segoe UI;font-size:16px'>Hi All,</span><br/><br/>");
//code goes here!!
//Get the SMTP server
SmtpClient client = new SmtpClient();
client.Host = properties.Site.WebApplication.OutboundMailServiceInstance.Server.Address;
// client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
myMailMessage.IsBodyHtml = true;
myMailMessage.Subject = subject;
myMailMessage.Body = mailBody.ToString();
myMailMessage.From = new MailAddress(fromField);
client.Send(myMailMessage);
}
but no emails are being sent. now inside my sharepoint farm i can send emails from sharepoint designer (Send Email activity) + if users add notifications they can receive,, so i am not sure why my above code is not working?
Thanks