Skip to content

Commit

Permalink
dfgv
Browse files Browse the repository at this point in the history
  • Loading branch information
Szachor committed May 14, 2014
1 parent a0a4374 commit f9dc0e5
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 17 deletions.
64 changes: 56 additions & 8 deletions MailSender/MailSender/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 9,77 @@ namespace MailSender
/// <summary>
///
/// </summary>



public class Mail
{
private List<String> tos;
private String content;
private String subject;


private List<Address> _tos;
private List<Attachments>_attachments;
private String _content;
private String _subject;
private bool html;

#region Properties
public List<Address> to
{
get { return this._tos; }
set { this._tos = value; }
}
public List<Address> attachments
{
get { return this._tos; }
set { this._tos = value; }
}
public string text
{
get { return this._content; }
set { this._content = value; }
}
public string subject
{
get { return this._subject; }
set { this._subject = value; }
}
#endregion
public class Address
{
private string _email;
public string email
{
get { return this._email; }
set { this._email = value; }
}
public Address(string email)
{
this._email = email;
}
}
public class Attachments
{

}

/// <summary>
///
/// </summary>
/// <param name="to"></param>
/// <param name="subject"></param>
/// <param name="content"></param>
/// <param name="_subject"></param>
/// <param name="_content"></param>
/// <param name="html"></param>
public Mail(String to, String subject, String content = "", bool html = false) : this(subject, content, html)
{
tos.Add(to);
_tos = new List<Address>();
_attachments = new List<Attachments>();
_tos.Add(new Address(to));
}

public Mail(String subject, String content = "", bool html = false)
{
this.subject = subject;
this.content = content;
this._subject = subject;
this._content = content;
this.html = html;
}
public bool AddRecipient(String recipient)
Expand Down
2 changes: 1 addition & 1 deletion MailSender/MailSender/MailSenderInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,7 @@ namespace MailSender
public interface MailSenderInterface
{
Object SendMail(Mail mail);
Object SendTestMail();
Object SendTestMail(Mail m);
Object TestKey();
Object SendersList();
}
Expand Down
10 changes: 10 additions & 0 deletions MailSender/MandrillMailSender/MandrillMailSender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 31,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp">
<HintPath>..\packages\RestSharp.104.4.0\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -40,6 46,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyJsonSeriallizer.cs" />
<Compile Include="MandrillMailSenderClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -49,6 56,9 @@
<Name>MailSender</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
112 changes: 106 additions & 6 deletions MailSender/MandrillMailSender/MandrillMailSenderClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,11 @@
using MailSender;
using Newtonsoft.Json.Linq;
using RestSharp;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using RestSharp.Serializers;
using Newtonsoft.Json;

namespace MandrillMailSender
{
public class MandrillMailSenderClass : MailSenderInterface
Expand All @@ -28,7 32,70 @@ public string Apikey
set { this.apikey = value; }
}
#endregion
#region JsonSerializer
#region PostClass
public class Post
{
string apikey;
public string key
{
get { return this.apikey; }

}
public class Message
{
string send_text;
string send_subject;

public string text
{
get { return this.send_text; }
}
public string subject
{
get { return this.send_subject; }
}
public Message()
{
send_text = "Test";
send_subject = "Test";
}
}
Message send_message;
public Message message
{
get { return this.send_message; }
set { this.send_message = value; }
}
string[] list;
public class To
{
private string _email;
private string _name;
public string email
{
get { return this._email; }
}
public string name
{
get { return this._name; }
}
}
public string[] to
{
get { return this.list; }
}

public Post(MandrillMailSenderClass mms)
{
send_message = new Message();
apikey = mms.apikey;
list = new string[10];
for(int i=0;i<10;i ){
list[i]="0" i;
}
}

};
#endregion

public MandrillMailSenderClass(String apikey)
Expand All @@ -38,25 105,58 @@ public MandrillMailSenderClass(String apikey)
}

public Object SendMail(Mail mail)
{
{

RestRequest request = new RestRequest("messages/send.json", Method.POST);
request.JsonSerializer = new MyJsonSerializer();
request.RequestFormat = DataFormat.Json;
request.AddBody(new { key = apikey, message = mail });
return GetJsonResponse(request);
}
public Object SendTestMail(Mail m)
{
return true;
}
public Object SendTestMail() { return false; }
public Object TestKey() { return false; }

public Object SendersList()
{
string post="";
RestRequest request = new RestRequest("senders/list.json");
RestRequest request = new RestRequest("senders/list.json", Method.POST);
request.JsonSerializer = new MyJsonSerializer();
//MyJsonSerializer serializer = new MyJsonSerializer();
request.RequestFormat = DataFormat.Json;
request.AddObject(new { key = this.apikey });
List<String> s = new List<String>();
s.Add("asdf");
s.Add("asdf123123");
//request.AddObject(new { to = new { email = "[email protected]" } });
//request.AddObject(new { key = this.apikey });
//request.AddObject(new Mail("Test", "Test", "Test"));
Mail m = new Mail("Test", "Test", "Test");
//request.AddObject(new { key = napraw(m) });
request.AddBody(new { key = apikey, message = m });
//request.AddParameter("\"key\"", serializer.Serialize(this.apikey), ParameterType.RequestBody);
//request.AddParameter("key", serializer.Serialize(m), ParameterType.RequestBody);
//var json = Json
//string json = JsonConvert.SerializeObject(product);
//request.AddParameter("application/json; charset=utf-8", new Post(this), ParameterType.RequestBody);
return GetJsonResponse(request);
}
public String napraw(Mail m)
{
MyJsonSerializer serializer = new MyJsonSerializer();
String result = apikey;
result = "\" ,";
result = serializer.Serialize(m);
result = ",\"smiec\":\"smiec";
return result;
}

private JObject GetJsonResponse(RestRequest request)
{
RestClient client = new RestClient(url);
IRestResponse response = client.Execute(request);
response.Content = "{\"list\":" response.Content '}';
response.Content = "{\"response\":" response.Content '}';
JObject json = JObject.Parse(response.Content);
return json;
}
Expand Down
Loading

0 comments on commit f9dc0e5

Please sign in to comment.