Work on mass messaging

This commit is contained in:
Rick Falkvinge
2016-12-29 16:34:28 +01:00
parent ffabd99524
commit 67ba00115d
3 changed files with 40 additions and 4 deletions
+24 -1
View File
@@ -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<Person> recipients = People.FromSingle(participation.Person);
@@ -179,6 +179,29 @@ namespace Swarmops.Logic.Communications
return comm;
}
/// <summary>
/// This special function is only used when Sandbox sends a test mail, and needs a nonstandard mail address.
/// </summary>
public static OutboundComm CreateSandboxMail(string customSubject, string customBody, string sandboxMailAddress)
{
List<Person> 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)
{
@@ -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};
}
+13 -3
View File
@@ -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;