Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Carbon.Email/Carbon.Email.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>http://project_url_here_or_delete_this_line/</projectUrl>
Comment thread
phrohdoh marked this conversation as resolved.
Outdated
<iconUrl>http://icon_url_here_or_delete_this_line/</iconUrl>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
</package>
2 changes: 2 additions & 0 deletions Carbon.Email/ISmtpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ void SendHtmlMessage(string replyto,
string cc, string subject, string htmlBody, Attachment attachment);

void SendMessage(MailMessage msg);

bool IsValidEmail(List<string> excludedDomains, string email);
}
}
21 changes: 21 additions & 0 deletions Carbon.Email/SendGridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ public SendGridClient(string host, string username, string password, int port =
Credentials = new NetworkCredential(username, password);
}

public bool IsValidEmail(List<string> excludedDomains, string email)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to pass the excluded Domains as paramerters . this method can read from the config. Also move to separate class and make static

{
try
{
MailAddress mail = new MailAddress(email);
if (excludedDomains.Any(dom => email.Split('@').Contains(dom)))
{
return false;
}
else
{
return true;
}
}
catch (Exception e)
{
return false;
}

}

public void SendHtmlMessage(string replyto, string from, string to, string cc, string subject, string htmlBody, Attachment attachment)
{
MailMessage msg = new MailMessage(from, to, subject, htmlBody);
Expand Down
1 change: 1 addition & 0 deletions CarbonTests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<configuration>
<appSettings>
<add key="Carbon.Ioc-CarbonTests.Ioc.IExample,CarbonTests" value="CarbonTests.Ioc.Example,CarbonTests"/>
<add key="Carbon.Ioc-CarbonTests.Email.ISmtpProvider,CarbonTests" value="CarbonTests.Email.EmailBlocker,CarbonTests"/>
</appSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
3 changes: 3 additions & 0 deletions CarbonTests/CarbonTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Email\EmailBlocker.cs" />
<Compile Include="Email\ISmtpProvider.cs" />
<Compile Include="Email\EmailTest.cs" />
<Compile Include="Ioc\Example.cs" />
<Compile Include="Ioc\IExample.cs" />
<Compile Include="Ioc\ContainerTest.cs" />
Expand Down
34 changes: 34 additions & 0 deletions CarbonTests/Email/EmailBlocker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace CarbonTests.Email
{
public class EmailBlocker : ISmtpProvider
{
public bool IsValidEmail(List<string> excludedDomains, string email)
{
try
{
MailAddress mail = new MailAddress(email);
if (excludedDomains.Any(dom => email.Split('@').Contains(dom)))
{
return false;
}
else
{
return true;
}
}
catch (Exception e)
{
return false;
}


}
}
}
26 changes: 26 additions & 0 deletions CarbonTests/Email/EmailTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Net.Mail;
using System.Threading;
using Carbon.Ioc;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CarbonTests.Email
{
[TestClass]
public class EmailTest
{
[TestMethod]
public void IsValidEmail()
{
ISmtpProvider p = Container.Get<ISmtpProvider>();
string email = "test@yahoo.com";
List<string> excludedDomains = new List<string>()
{
"sharklasers.com",
"gurilla.com"
};
Assert.IsTrue(p.IsValidEmail(excludedDomains, email));
}
}
}
13 changes: 13 additions & 0 deletions CarbonTests/Email/ISmtpProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarbonTests.Email
{
interface ISmtpProvider
{
bool IsValidEmail(List<string> excludedDomains, string email);
}
}