diff --git a/Logic/Communications/ICommsRenderer.cs b/Logic/Communications/ICommsRenderer.cs index 8b3e0f4d..5baad32b 100644 --- a/Logic/Communications/ICommsRenderer.cs +++ b/Logic/Communications/ICommsRenderer.cs @@ -11,15 +11,15 @@ namespace Swarmops.Logic.Communications /// public interface ICommsRenderer { - RenderedComms RenderComm(OutboundComm comm, Person person); + RenderedComm RenderComm(Person person); } - public class RenderedComms: Dictionary + public class RenderedComm: Dictionary { // typeset for readability } - public enum CommsRenderPart + public enum CommRenderPart { Unknown = 0, SenderName, diff --git a/Logic/Communications/ICommsTransmitter.cs b/Logic/Communications/ICommsTransmitter.cs index 7c1747ec..6634c6b3 100644 --- a/Logic/Communications/ICommsTransmitter.cs +++ b/Logic/Communications/ICommsTransmitter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Swarmops.Logic.Communications.Transmission; using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Communications @@ -13,6 +14,6 @@ namespace Swarmops.Logic.Communications /// /// The piece of communications to send. /// The person to send to. - void Transmit(OutboundComm comm, Person person); + void Transmit(PayloadEnvelope envelope, Person person); } } diff --git a/Logic/Communications/Transmission/NotificationPayload.cs b/Logic/Communications/Transmission/NotificationPayload.cs index 4cacbeca..8408e5d5 100644 --- a/Logic/Communications/Transmission/NotificationPayload.cs +++ b/Logic/Communications/Transmission/NotificationPayload.cs @@ -62,14 +62,14 @@ namespace Swarmops.Logic.Communications.Transmission #region Implementation of ICommsRenderer - public RenderedComms RenderComm(OutboundComm comm, Person person) + public RenderedComm RenderComm(Person person) { - RenderedComms result = new RenderedComms(); + RenderedComm result = new RenderedComm(); - result[CommsRenderPart.Subject] = GetSubject(); - result[CommsRenderPart.BodyText] = GetBody(); - result[CommsRenderPart.SenderName] = "Swarmops Administrative"; - result[CommsRenderPart.SenderMail] = "admin@swarmops.com"; + result[CommRenderPart.Subject] = GetSubject(); + result[CommRenderPart.BodyText] = GetBody(); + result[CommRenderPart.SenderName] = "Swarmops Administrative"; + result[CommRenderPart.SenderMail] = "admin@swarmops.com"; return result; } diff --git a/Logic/Communications/Transmission/PayloadBase.cs b/Logic/Communications/Transmission/PayloadBase.cs index a9a362e4..cfc0cc54 100644 --- a/Logic/Communications/Transmission/PayloadBase.cs +++ b/Logic/Communications/Transmission/PayloadBase.cs @@ -21,7 +21,7 @@ namespace Swarmops.Logic.Communications.Transmission return Encoding.Default.GetString(xmlBytes); } - static T FromXml (string xml) + public static T FromXml (string xml) { var serializer = new XmlSerializer(typeof(T)); diff --git a/Utility/Communications/CommsTransmitterMail.cs b/Utility/Communications/CommsTransmitterMail.cs index d1228a4c..2e938fa4 100644 --- a/Utility/Communications/CommsTransmitterMail.cs +++ b/Utility/Communications/CommsTransmitterMail.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Mail; using System.Text; using Swarmops.Logic.Communications; +using Swarmops.Logic.Communications.Transmission; using Swarmops.Logic.Swarm; namespace Swarmops.Utility.Communications @@ -11,9 +13,39 @@ namespace Swarmops.Utility.Communications { // To be implemented - public void Transmit(OutboundComm comm, Person person) + public void Transmit(PayloadEnvelope envelope, Person person) { - throw new NotImplementedException(); + if (envelope.PayloadClass != "Swarmops.Logic.Communications.Transmission.NotificationPayload") + { + throw new NotImplementedException(); + } + + ICommsRenderer renderer = NotificationPayload.FromXml(envelope.PayloadXml); + + RenderedComm comm = renderer.RenderComm(person); + + MailMessage mail = new MailMessage(); + + // This is a rather simple mail (no images or stuff like that) + + mail.From = new MailAddress(comm[CommRenderPart.SenderMail], comm[CommRenderPart.SenderMail], Encoding.UTF8); + mail.To.Add(new MailAddress(person.Email, person.Name)); + + mail.Subject = comm[CommRenderPart.Subject]; + mail.Body = comm[CommRenderPart.Subject]; + mail.SubjectEncoding = Encoding.UTF8; + mail.BodyEncoding = Encoding.UTF8; + + SmtpClient mailClient = new SmtpClient("192.168.80.204"); // Fix this - for development use only + + try + { + mailClient.Send(mail); + } + catch (Exception e) + { + throw new OutboundCommTransmitException("Cannot send mail to " + person.Email, e); + } } }