Skip to content

Commit

Permalink
implement email client
Browse files Browse the repository at this point in the history
  • Loading branch information
zlzforever committed Apr 21, 2016
1 parent 2e131c6 commit a17e258
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 202 deletions.
602 changes: 457 additions & 145 deletions src/Java2Dotnet.Spider.Common/EmailClient.cs

Large diffs are not rendered by default.

36 changes: 0 additions & 36 deletions src/Java2Dotnet.Spider.Common/EmailUtil2.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
<Compile Include="..\DirectoryExtensions.cs">
<Link>DirectoryExtensions.cs</Link>
</Compile>
<Compile Include="..\EmailClient.cs">
<Link>EmailClient.cs</Link>
</Compile>
<Compile Include="..\EmailUtil.cs">
<Link>EmailUtil.cs</Link>
</Compile>
<Compile Include="..\EmailUtil2.cs">
<Link>EmailUtil2.cs</Link>
</Compile>
<Compile Include="..\Encrypt.cs">
<Link>Encrypt.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,26 @@ private Validations GetValidations(JObject validations)
}

Validations result = new Validations();
var dataSource = validations.SelectToken("$.DataSource")?.ToObject<DataSource>();
var connectString = validations.SelectToken("$.ConnectString")?.ToString();
var reportTo = validations.SelectToken("$.ReportTo")?.ToString();
var corporation = validations.SelectToken("$.Corporation")?.ToString();
if (dataSource == null || string.IsNullOrEmpty(connectString) || string.IsNullOrEmpty(reportTo))
var source = validations.SelectToken("$.DataSource");
if (source == null)
{
return null;
}
result.Source = dataSource.Value;
result.ConnectString = connectString;
result.Corporation = corporation;
result.ReportTo = reportTo;

result.Source = source.ToObject<DataSource>();
result.ConnectString = validations.SelectToken("$.ConnectString")?.ToString();
result.EmailTo = validations.SelectToken("$.ReportTo")?.ToString();
result.Corporation = validations.SelectToken("$.Corporation")?.ToString();
result.EmailPassword = validations.SelectToken("$.EmailPassword")?.ToString();
var port = validations.SelectToken("$.EmailSmtpPort");
result.EmailSmtpPort = port == null ? 25 : int.Parse(port.ToString());
result.EmailSmtpServer = validations.SelectToken("$.EmailSmtpServer")?.ToString();
result.EmailUser = validations.SelectToken("$.EmailUser")?.ToString();

if (string.IsNullOrEmpty(result.ConnectString) || string.IsNullOrEmpty(result.EmailTo) || string.IsNullOrEmpty(result.EmailPassword) || string.IsNullOrEmpty(result.EmailSmtpServer) || string.IsNullOrEmpty(result.EmailUser))
{
return null;
}

foreach (var validation in validations.SelectTokens("$.Rules[*]"))
{
var type = validation.SelectToken("$.Type")?.ToObject<Validation.Types>();
Expand Down Expand Up @@ -329,7 +336,7 @@ private Downloader GetDownloader(JObject jobject)
break;
#else
throw new SpiderExceptoin("UNSPORT WEBDRIVER DOWNLOADER.");
#endif
#endif
}
case Configuration.Downloader.Types.HttpClientDownloader:
{
Expand Down
11 changes: 10 additions & 1 deletion src/Java2Dotnet.Spider.Extension/Configuration/Validation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ namespace Java2Dotnet.Spider.Extension.Configuration
public class Validations
{
public string Corporation { get; set; }
public string EmailUser { get; set; }
public string EmailPassword { get; set; }
public string EmailSmtpServer { get; set; }
public int EmailSmtpPort { get; set; } = 25;
public string EmailTo { get; set; }
public string ConnectString { get; set; }
public DataSource Source { get; set; } = DataSource.MySql;
public string ReportTo { get; set; }
public List<Validation> Rules { get; set; }

internal List<IValidation> GetValidations()
{
if (string.IsNullOrEmpty(ConnectString) || string.IsNullOrEmpty(EmailTo) || string.IsNullOrEmpty(EmailPassword) || string.IsNullOrEmpty(EmailSmtpServer) || string.IsNullOrEmpty(EmailUser))
{
return null;
}

var conn = DataSourceUtil.GetConnection(Source, ConnectString);
List<IValidation> results = new List<IValidation>();
foreach (var rule in Rules)
Expand Down
5 changes: 4 additions & 1 deletion src/Java2Dotnet.Spider.Extension/ContextSpider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ private void DoValidate()
}
string mailBody = builder.Build();

EmailUtil2.Send($"{Name} " + "validation report", _spiderContext.Validations.ReportTo, mailBody);
using (EmailClient client = new EmailClient(_spiderContext.Validations.EmailSmtpServer, _spiderContext.Validations.EmailUser, _spiderContext.Validations.EmailPassword, _spiderContext.Validations.EmailSmtpPort))
{
client.SendMail(new EmaillMessage($"{Name} " + "validation report", mailBody, _spiderContext.Validations.EmailTo) { IsHtml = true });
}
}
}
else
Expand Down
7 changes: 3 additions & 4 deletions src/Java2Dotnet.Spider.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ public static void Main(string[] args)
//spider.Run(args);


Regex regex = new Regex(@"\d");
var m = regex.Match("6");

Console.WriteLine("OK");
EmailClient client = new EmailClient("smtp.163.com", "[email protected]", "zousong.88");
var msg = new EmaillMessage("test", "test", "[email protected]" );
client.SendMail(msg);
}

private static void TestStatusServer()
Expand Down
4 changes: 3 additions & 1 deletion src/Java2Dotnet.Spider.Test/net45/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ redisPassword:#frAiI^MtFxh3Ks&swrnVyzAtRTq%w
redialRedisHost:redis
redialRedisPassword:#frAiI^MtFxh3Ks&swrnVyzAtRTq%w
logserver:http://localhost:62823/api/log/uploadlog
emailApiHost:http://localhost:62823/api/email?action=send
emailUser:[email protected]
emailPass:zousong.88
emailHost:smtp.163.com

0 comments on commit a17e258

Please sign in to comment.