C# : Handling not sent email exception

Im stuck with problem as some of the system users are “nonactive” users and my function is not handling exception of not sending email to “nonactive” users. Function send email to users even if they are nonactive in system.

private static bool Postepowanie_ObslugaPodstawowa(AlertTyp typPowiadomienia, string statusDescr, int podanieId, IUzytkownik sender, IEnumerable<IUzytkownik> recipients)
    SzablonPowiadomien szablon = PobierzSzablon(typPowiadomienia);
    Postepowanie postepowanie = Postepowanie.GetById<Postepowanie(podanieId);

    string body = szablon.Tresc.MakeFormat(statusDescr, sender.FullName, postepowanie.NazwaZamowienia, GetFullUrl(string.Format("PostepowanieDane.aspx?{0}={1}", TextConsts.Id, podanieId)));
    string subject = szablon.Temat.MakeFormat(statusDescr);
    return SendEmail(recipients.AsQueryable().Select(it => it.Email).ToArray<string>(), subject, body);

public interface IUzytkownik
int Id { get; }
int KomOrgId { get; }
bool Aktywny { get; }
string Email { get; }
string FullName { get; }
bool HasRights<T>(params T[] _perms) where T : struct, IConvertible;


If recipients are taken from the database with the information stored in members of IUzytkownikand there is an active column of boolean type holding information if user is active, you can simply do this:

return SendEmail(recipients.Where(it => it.Aktywny==true).Select(it => it.Email).ToArray<string>(), subject, body);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s