diff --git a/Logic/Communications/OutboundComm.cs b/Logic/Communications/OutboundComm.cs index 75bbb476..53431d2d 100644 --- a/Logic/Communications/OutboundComm.cs +++ b/Logic/Communications/OutboundComm.cs @@ -158,7 +158,7 @@ namespace Swarmops.Logic.Communications } - public static OutboundComm CreateParticipantMail (string customSubject, string customBody, Participation participation, + public static OutboundComm CreateParticipantMail(string customSubject, string customBody, Participation participation, Person actingPerson) { List recipients = People.FromSingle(participation.Person); @@ -179,6 +179,29 @@ namespace Swarmops.Logic.Communications return comm; } + /// + /// This special function is only used when Sandbox sends a test mail, and needs a nonstandard mail address. + /// + public static OutboundComm CreateSandboxMail(string customSubject, string customBody, string sandboxMailAddress) + { + List recipients = People.FromSingle(Person.FromIdentity(1)); + + OutboundComm comm = OutboundComm.Create(null, null, Organization.Sandbox, + null /* resolver */, null, + CommTransmitterClass.CommsTransmitterMail, + new PayloadEnvelope(new ParticipantMailPayload(sandboxMailAddress + "|" + customSubject, customBody, recipients[0].GetMemberships()[0], recipients[0])).ToXml(), + OutboundCommPriority.Low); + + foreach (Person person in recipients) + { + comm.AddRecipient(person); // needed for pickup + } + + comm.Resolved = true; + + return comm; + } + public static OutboundComm CreateNotification (Organization organization, string notificationResourceString, People recipients = null) { diff --git a/Site/Pages/v5/Comms/SendMassMessage.aspx.cs b/Site/Pages/v5/Comms/SendMassMessage.aspx.cs index 93dc2bbd..0b9fb8d2 100644 --- a/Site/Pages/v5/Comms/SendMassMessage.aspx.cs +++ b/Site/Pages/v5/Comms/SendMassMessage.aspx.cs @@ -5,6 +5,7 @@ using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; using Resources; +using Swarmops.Logic.Communications; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; using Swarmops.Logic.Swarm; @@ -106,6 +107,8 @@ namespace Swarmops.Frontend.Pages.Comms public static AjaxCallResult ExecuteSend(int recipientTypeId, int geographyId, string mode, string subject, string body, string dummyMail, bool live) { + OutboundComm.CreateSandboxMail(subject, body, "test@falkvinge.net"); + return new AjaxCallResult {Success = false}; } diff --git a/Utility/Communications/CommsTransmitterMail.cs b/Utility/Communications/CommsTransmitterMail.cs index 0d55843b..fc39e1ff 100644 --- a/Utility/Communications/CommsTransmitterMail.cs +++ b/Utility/Communications/CommsTransmitterMail.cs @@ -51,11 +51,23 @@ namespace Swarmops.Utility.Communications throw new OutboundCommTransmitException("No valid mail address for " + person.Canonical); } + mail.Subject = (string)comm[CommRenderPart.Subject]; + mail.SubjectEncoding = Encoding.UTF8; + try { mail.From = new MailAddress ((string) comm[CommRenderPart.SenderMail], (string) comm[CommRenderPart.SenderName], Encoding.UTF8); - mail.To.Add (new MailAddress (person.Mail, person.Name)); + + // SPECIAL CASE for sandbox mails -- ugly code but wtf + if (person.Identity == 1 && PilotInstallationIds.DevelopmentSandbox == SystemSettings.InstallationId) + { + mail.To.Add(new MailAddress("test@falkvinge.net", "Swarmops Sandbox Administrator")); + } + else // regular case to be used... like everywhere else except for the sandbox test + { + mail.To.Add(new MailAddress(person.Mail, person.Name)); + } } catch (FormatException e) { @@ -71,9 +83,7 @@ namespace Swarmops.Utility.Communications string mailBodyHtml = comm.ContainsKey(CommRenderPart.BodyHtml)? (string)comm[CommRenderPart.BodyHtml]: string.Empty; mailBodyHtml = mailBodyHtml.Replace("[Addressee]", person.Canonical); - mail.Subject = (string)comm[CommRenderPart.Subject]; mail.Body = mailBodyText; - mail.SubjectEncoding = Encoding.UTF8; mail.BodyEncoding = Encoding.UTF8; string smtpServer = _smtpServerCache;