Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
Added bulk send capabilities
  • Loading branch information
bryantbhowell committed Apr 14, 2017
1 parent 1f8a4d6 commit cb5fb39
Show file tree
Hide file tree
Showing 9 changed files with 753 additions and 187 deletions.
5 changes: 4 additions & 1 deletion Behold Emailer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<RootNamespace>Behold_Emailer</RootNamespace>
<AssemblyName>Behold Emailer</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
Expand Down Expand Up @@ -50,7 +51,9 @@
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
39 changes: 31 additions & 8 deletions BeholdEmailer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void log(string l)
}
}

public void email_file_from_template(string from_user, string to_user, string subject, string simple_message_text, string filename_to_attach)
public void email_file_from_template(string from_user, string[] to_users, string[] cc_users, string[] bcc_users, string subject, string simple_message_text, string filename_to_attach)
{
string message_text = "";
// Load Text template
Expand All @@ -93,10 +93,33 @@ public void email_file_from_template(string from_user, string to_user, string su
message_text = simple_message_text;
}

MailMessage message = new MailMessage(from_user, to_user);
MailMessage message = new MailMessage(from_user, to_users[0]);
message.Body = message_text;
message.Subject = subject;

var to_collect = message.To;
var cc_collect = message.CC;
var bcc_collect = message.Bcc;
for (var i = 1; i < to_users.Length; i++)
{
var add = new MailAddress(to_users[i]);
to_collect.Add(add);
}

for (var i = 0; i < cc_users.Length; i++)
{
if (cc_users[i] == "") { continue; }
var add = new MailAddress(cc_users[i]);
cc_collect.Add(add);
}

for (var i = 0; i < bcc_users.Length; i++)
{
if (bcc_users[i] == "") { continue; }
var add = new MailAddress(bcc_users[i]);
bcc_collect.Add(add);
}

// Load HTML template as alternative
if (this.html_email_template_filename != "")
{
Expand Down Expand Up @@ -127,7 +150,7 @@ public void email_file_from_template(string from_user, string to_user, string su
public string generate_export_and_watermark(string view_user, string view_location, string content_type,
Dictionary<string, string> view_filter_dictionary, Watermarker watermark)
{
string filename_to_attach = this.tabcmd.create_export(content_type, view_location, new Dictionary<string, string>(), view_user, "exported_workbook");
string filename_to_attach = this.tabcmd.create_export(content_type, view_location, view_filter_dictionary, view_user, "exported_workbook");
this.log(String.Format("PDF created and saved successfully as {0}", filename_to_attach));

// Watermark the PDF (working copy)
Expand All @@ -140,14 +163,14 @@ public string generate_export_and_watermark(string view_user, string view_locati
return filename_to_attach;
}

public bool generate_email_from_view(string email_from_user, string email_to_user, string email_subject, string email_template_name,
public bool generate_email_from_view(string email_from_user, string[] email_to, string[] email_cc, string[] email_bcc, string email_subject, string email_template_name,
string view_user, string view_location, string email_content_type, Dictionary<string, string> view_filter_dictionary, Watermarker watermark)
{
this.log(String.Format("Creating PDF export from tabcmd for {0} for user {1}", view_location, view_user));
try
{

string filename_to_attach = this.generate_export_and_watermark(view_user, view_location, email_content_type, new Dictionary<string, string>(), watermark);
string filename_to_attach = this.generate_export_and_watermark(view_user, view_location, email_content_type, view_filter_dictionary, watermark);
this.log(String.Format("PDF created and saved successfully as {0}", filename_to_attach));

// Copy the file with a new name so that it can be archived
Expand All @@ -165,8 +188,8 @@ public bool generate_email_from_view(string email_from_user, string email_to_use

File.Copy(filename_to_attach, final_filename, true);

this.log(String.Format("Sending e-mail of exported and watermarked PDF to {0}", email_to_user));
this.email_file_from_template(email_from_user, email_to_user, email_subject, email_template_name, final_filename);
this.log(String.Format("Sending e-mail of exported and watermarked PDF to {0}", email_to[0]));
this.email_file_from_template(email_from_user, email_to, email_cc, email_bcc, email_subject, email_template_name, final_filename);
this.log(String.Format("Removing original file {0}", filename_to_attach));
File.Delete(filename_to_attach);

Expand Down Expand Up @@ -205,7 +228,7 @@ public bool generate_emails_from_named_schedule_in_repository(string schedule_na
this.log(String.Format("Generating e-mail of view {0} on site {1} for {2} at {3}", view_location, site, user, user_email));


bool result = this.generate_email_from_view(from_user, user_email, email_subject, "", user, view_location, "fullpdf",
bool result = this.generate_email_from_view(from_user, new string[1] {user_email}, new string[0]{}, new string[0]{}, email_subject, "", user, view_location, "fullpdf",
new Dictionary<string,string>(), watermarker);
if (all_suceeded == true && result == false){
all_suceeded = false;
Expand Down
120 changes: 120 additions & 0 deletions Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Loading

0 comments on commit cb5fb39

Please sign in to comment.