mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 11:10:23 +12:00
Added automatic email send option to specific email address
This commit is contained in:
parent
cb7a621b73
commit
5a87688005
|
@ -36,36 +36,50 @@ public class EmailFileUploaderService : FileUploaderService
|
|||
|
||||
public override bool CheckConfig(UploadersConfig config)
|
||||
{
|
||||
return !string.IsNullOrEmpty(config.EmailSmtpServer) && config.EmailSmtpPort > 0 && !string.IsNullOrEmpty(config.EmailFrom) &&
|
||||
!string.IsNullOrEmpty(config.EmailPassword);
|
||||
return !string.IsNullOrEmpty(config.EmailSmtpServer) && config.EmailSmtpPort > 0 && !string.IsNullOrEmpty(config.EmailFrom) && !string.IsNullOrEmpty(config.EmailPassword);
|
||||
}
|
||||
|
||||
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
|
||||
{
|
||||
using (EmailForm emailForm = new EmailForm(config.EmailRememberLastTo ? config.EmailLastTo : "",
|
||||
config.EmailDefaultSubject, config.EmailDefaultBody))
|
||||
if (config.EmailAutomaticSend && !string.IsNullOrEmpty(config.EmailAutomaticSendTo))
|
||||
{
|
||||
if (emailForm.ShowDialog() == DialogResult.OK)
|
||||
return new Email()
|
||||
{
|
||||
if (config.EmailRememberLastTo)
|
||||
SmtpServer = config.EmailSmtpServer,
|
||||
SmtpPort = config.EmailSmtpPort,
|
||||
FromEmail = config.EmailFrom,
|
||||
Password = config.EmailPassword,
|
||||
ToEmail = config.EmailAutomaticSendTo,
|
||||
Subject = config.EmailDefaultSubject,
|
||||
Body = config.EmailDefaultBody
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
using (EmailForm emailForm = new EmailForm(config.EmailRememberLastTo ? config.EmailLastTo : "", config.EmailDefaultSubject, config.EmailDefaultBody))
|
||||
{
|
||||
if (emailForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
config.EmailLastTo = emailForm.ToEmail;
|
||||
}
|
||||
if (config.EmailRememberLastTo)
|
||||
{
|
||||
config.EmailLastTo = emailForm.ToEmail;
|
||||
}
|
||||
|
||||
return new Email
|
||||
return new Email()
|
||||
{
|
||||
SmtpServer = config.EmailSmtpServer,
|
||||
SmtpPort = config.EmailSmtpPort,
|
||||
FromEmail = config.EmailFrom,
|
||||
Password = config.EmailPassword,
|
||||
ToEmail = emailForm.ToEmail,
|
||||
Subject = emailForm.Subject,
|
||||
Body = emailForm.Body
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
SmtpServer = config.EmailSmtpServer,
|
||||
SmtpPort = config.EmailSmtpPort,
|
||||
FromEmail = config.EmailFrom,
|
||||
Password = config.EmailPassword,
|
||||
ToEmail = emailForm.ToEmail,
|
||||
Subject = emailForm.Subject,
|
||||
Body = emailForm.Body
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
taskInfo.StopRequested = true;
|
||||
taskInfo.StopRequested = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,6 +100,11 @@ public class Email : FileUploader
|
|||
public string Subject { get; set; }
|
||||
public string Body { get; set; }
|
||||
|
||||
public void Send()
|
||||
{
|
||||
Send(ToEmail, Subject, Body);
|
||||
}
|
||||
|
||||
public void Send(string toEmail, string subject, string body)
|
||||
{
|
||||
Send(toEmail, subject, body, null, null);
|
||||
|
@ -93,7 +112,7 @@ public void Send(string toEmail, string subject, string body)
|
|||
|
||||
public void Send(string toEmail, string subject, string body, Stream stream, string fileName)
|
||||
{
|
||||
SmtpClient smtp = new SmtpClient
|
||||
using (SmtpClient smtp = new SmtpClient()
|
||||
{
|
||||
Host = SmtpServer,
|
||||
Port = SmtpPort,
|
||||
|
@ -101,20 +120,21 @@ public void Send(string toEmail, string subject, string body, Stream stream, str
|
|||
DeliveryMethod = SmtpDeliveryMethod.Network,
|
||||
UseDefaultCredentials = false,
|
||||
Credentials = new NetworkCredential(FromEmail, Password)
|
||||
};
|
||||
|
||||
using (MailMessage message = new MailMessage(FromEmail, toEmail))
|
||||
})
|
||||
{
|
||||
message.Subject = subject;
|
||||
message.Body = body;
|
||||
|
||||
if (stream != null)
|
||||
using (MailMessage message = new MailMessage(FromEmail, toEmail))
|
||||
{
|
||||
Attachment attachment = new Attachment(stream, fileName);
|
||||
message.Attachments.Add(attachment);
|
||||
}
|
||||
message.Subject = subject;
|
||||
message.Body = body;
|
||||
|
||||
smtp.Send(message);
|
||||
if (stream != null)
|
||||
{
|
||||
Attachment attachment = new Attachment(stream, fileName);
|
||||
message.Attachments.Add(attachment);
|
||||
}
|
||||
|
||||
smtp.Send(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
2
ShareX.UploadersLib/Forms/EmailForm.Designer.cs
generated
2
ShareX.UploadersLib/Forms/EmailForm.Designer.cs
generated
|
@ -100,6 +100,8 @@ private void InitializeComponent()
|
|||
this.Controls.Add(this.txtToEmail);
|
||||
this.Controls.Add(this.lblToEmail);
|
||||
this.Name = "EmailForm";
|
||||
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
|
||||
this.Shown += new System.EventHandler(this.EmailForm_Shown);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
|
|
|
@ -48,6 +48,11 @@ public EmailForm(string toEmail, string subject, string body) : this()
|
|||
txtMessage.Text = body;
|
||||
}
|
||||
|
||||
private void EmailForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
txtMessage.Focus();
|
||||
}
|
||||
|
||||
private void btnSend_Click(object sender, EventArgs e)
|
||||
{
|
||||
ToEmail = txtToEmail.Text;
|
||||
|
|
|
@ -123,7 +123,7 @@
|
|||
</data>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="lblToEmail.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>11, 16</value>
|
||||
<value>5, 8</value>
|
||||
</data>
|
||||
<data name="lblToEmail.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>51, 13</value>
|
||||
|
@ -148,16 +148,16 @@
|
|||
</data>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="txtToEmail.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
<value>Top, Bottom, Left, Right</value>
|
||||
</data>
|
||||
<data name="txtToEmail.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>72, 12</value>
|
||||
<value>8, 24</value>
|
||||
</data>
|
||||
<data name="txtToEmail.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>216, 20</value>
|
||||
<value>296, 20</value>
|
||||
</data>
|
||||
<data name="txtToEmail.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>0</value>
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>txtToEmail.Name" xml:space="preserve">
|
||||
<value>txtToEmail</value>
|
||||
|
@ -175,7 +175,7 @@
|
|||
<value>True</value>
|
||||
</data>
|
||||
<data name="lblSubject.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>11, 40</value>
|
||||
<value>5, 48</value>
|
||||
</data>
|
||||
<data name="lblSubject.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>46, 13</value>
|
||||
|
@ -199,16 +199,16 @@
|
|||
<value>5</value>
|
||||
</data>
|
||||
<data name="txtSubject.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
<value>Top, Bottom, Left, Right</value>
|
||||
</data>
|
||||
<data name="txtSubject.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>72, 36</value>
|
||||
<value>8, 64</value>
|
||||
</data>
|
||||
<data name="txtSubject.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>216, 20</value>
|
||||
<value>296, 20</value>
|
||||
</data>
|
||||
<data name="txtSubject.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>1</value>
|
||||
<value>3</value>
|
||||
</data>
|
||||
<data name=">>txtSubject.Name" xml:space="preserve">
|
||||
<value>txtSubject</value>
|
||||
|
@ -226,7 +226,7 @@
|
|||
<value>True</value>
|
||||
</data>
|
||||
<data name="lblMessage.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>11, 64</value>
|
||||
<value>5, 88</value>
|
||||
</data>
|
||||
<data name="lblMessage.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>53, 13</value>
|
||||
|
@ -253,16 +253,16 @@
|
|||
<value>Top, Bottom, Left, Right</value>
|
||||
</data>
|
||||
<data name="txtMessage.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>72, 60</value>
|
||||
<value>8, 104</value>
|
||||
</data>
|
||||
<data name="txtMessage.Multiline" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="txtMessage.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>216, 164</value>
|
||||
<value>296, 160</value>
|
||||
</data>
|
||||
<data name="txtMessage.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>2</value>
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name=">>txtMessage.Name" xml:space="preserve">
|
||||
<value>txtMessage</value>
|
||||
|
@ -280,13 +280,13 @@
|
|||
<value>Bottom, Right</value>
|
||||
</data>
|
||||
<data name="btnSend.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>136, 232</value>
|
||||
<value>104, 272</value>
|
||||
</data>
|
||||
<data name="btnSend.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>72, 24</value>
|
||||
<value>96, 24</value>
|
||||
</data>
|
||||
<data name="btnSend.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
<value>6</value>
|
||||
</data>
|
||||
<data name="btnSend.Text" xml:space="preserve">
|
||||
<value>Send</value>
|
||||
|
@ -307,13 +307,13 @@
|
|||
<value>Bottom, Right</value>
|
||||
</data>
|
||||
<data name="btnCancel.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>216, 232</value>
|
||||
<value>208, 272</value>
|
||||
</data>
|
||||
<data name="btnCancel.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>72, 24</value>
|
||||
<value>96, 24</value>
|
||||
</data>
|
||||
<data name="btnCancel.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>3</value>
|
||||
<value>7</value>
|
||||
</data>
|
||||
<data name="btnCancel.Text" xml:space="preserve">
|
||||
<value>Cancel</value>
|
||||
|
@ -337,7 +337,7 @@
|
|||
<value>6, 13</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>298, 265</value>
|
||||
<value>312, 304</value>
|
||||
</data>
|
||||
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
|
||||
<value>CenterScreen</value>
|
||||
|
|
|
@ -390,7 +390,6 @@ private void InitializeComponent()
|
|||
this.cboSharedFolderImages = new System.Windows.Forms.ComboBox();
|
||||
this.ucLocalhostAccounts = new ShareX.UploadersLib.AccountsControl();
|
||||
this.tpEmail = new System.Windows.Forms.TabPage();
|
||||
this.cbEmailConfirm = new System.Windows.Forms.CheckBox();
|
||||
this.lblEmailSmtpServer = new System.Windows.Forms.Label();
|
||||
this.lblEmailPassword = new System.Windows.Forms.Label();
|
||||
this.cbEmailRememberLastTo = new System.Windows.Forms.CheckBox();
|
||||
|
@ -536,6 +535,8 @@ private void InitializeComponent()
|
|||
this.lblWidthHint = new System.Windows.Forms.Label();
|
||||
this.ttlvMain = new ShareX.HelpersLib.TabToListView();
|
||||
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
||||
this.cbEmailAutomaticSend = new System.Windows.Forms.CheckBox();
|
||||
this.txtEmailAutomaticSendTo = new System.Windows.Forms.TextBox();
|
||||
this.tpOtherUploaders.SuspendLayout();
|
||||
this.tcOtherUploaders.SuspendLayout();
|
||||
this.tpTwitter.SuspendLayout();
|
||||
|
@ -3234,7 +3235,8 @@ private void InitializeComponent()
|
|||
//
|
||||
// tpEmail
|
||||
//
|
||||
this.tpEmail.Controls.Add(this.cbEmailConfirm);
|
||||
this.tpEmail.Controls.Add(this.txtEmailAutomaticSendTo);
|
||||
this.tpEmail.Controls.Add(this.cbEmailAutomaticSend);
|
||||
this.tpEmail.Controls.Add(this.lblEmailSmtpServer);
|
||||
this.tpEmail.Controls.Add(this.lblEmailPassword);
|
||||
this.tpEmail.Controls.Add(this.cbEmailRememberLastTo);
|
||||
|
@ -3252,13 +3254,6 @@ private void InitializeComponent()
|
|||
this.tpEmail.Name = "tpEmail";
|
||||
this.tpEmail.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// cbEmailConfirm
|
||||
//
|
||||
resources.ApplyResources(this.cbEmailConfirm, "cbEmailConfirm");
|
||||
this.cbEmailConfirm.Name = "cbEmailConfirm";
|
||||
this.cbEmailConfirm.UseVisualStyleBackColor = true;
|
||||
this.cbEmailConfirm.CheckedChanged += new System.EventHandler(this.chkEmailConfirm_CheckedChanged);
|
||||
//
|
||||
// lblEmailSmtpServer
|
||||
//
|
||||
resources.ApplyResources(this.lblEmailSmtpServer, "lblEmailSmtpServer");
|
||||
|
@ -4299,6 +4294,19 @@ private void InitializeComponent()
|
|||
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
||||
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
|
||||
//
|
||||
// cbEmailAutomaticSend
|
||||
//
|
||||
resources.ApplyResources(this.cbEmailAutomaticSend, "cbEmailAutomaticSend");
|
||||
this.cbEmailAutomaticSend.Name = "cbEmailAutomaticSend";
|
||||
this.cbEmailAutomaticSend.UseVisualStyleBackColor = true;
|
||||
this.cbEmailAutomaticSend.CheckedChanged += new System.EventHandler(this.cbEmailAutomaticSend_CheckedChanged);
|
||||
//
|
||||
// txtEmailAutomaticSendTo
|
||||
//
|
||||
resources.ApplyResources(this.txtEmailAutomaticSendTo, "txtEmailAutomaticSendTo");
|
||||
this.txtEmailAutomaticSendTo.Name = "txtEmailAutomaticSendTo";
|
||||
this.txtEmailAutomaticSendTo.TextChanged += new System.EventHandler(this.txtEmailAutomaticSendTo_TextChanged);
|
||||
//
|
||||
// UploadersConfigForm
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
|
@ -4627,7 +4635,6 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.TextBox txtJiraHost;
|
||||
private System.Windows.Forms.Label lblJiraHost;
|
||||
private OAuthControl oAuthJira;
|
||||
private System.Windows.Forms.CheckBox cbEmailConfirm;
|
||||
private System.Windows.Forms.Label lblEmailSmtpServer;
|
||||
private System.Windows.Forms.Label lblEmailPassword;
|
||||
private System.Windows.Forms.CheckBox cbEmailRememberLastTo;
|
||||
|
@ -4960,5 +4967,7 @@ private void InitializeComponent()
|
|||
public System.Windows.Forms.TabPage tpPolr;
|
||||
public System.Windows.Forms.TabPage tpTwitter;
|
||||
public System.Windows.Forms.TabPage tpCustomUploaders;
|
||||
private System.Windows.Forms.TextBox txtEmailAutomaticSendTo;
|
||||
private System.Windows.Forms.CheckBox cbEmailAutomaticSend;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -439,10 +439,12 @@ public void LoadSettings()
|
|||
nudEmailSmtpPort.SetValue(Config.EmailSmtpPort);
|
||||
txtEmailFrom.Text = Config.EmailFrom;
|
||||
txtEmailPassword.Text = Config.EmailPassword;
|
||||
cbEmailConfirm.Checked = Config.EmailConfirmSend;
|
||||
cbEmailRememberLastTo.Checked = Config.EmailRememberLastTo;
|
||||
txtEmailDefaultSubject.Text = Config.EmailDefaultSubject;
|
||||
txtEmailDefaultBody.Text = Config.EmailDefaultBody;
|
||||
cbEmailAutomaticSend.Checked = Config.EmailAutomaticSend;
|
||||
txtEmailAutomaticSendTo.Enabled = Config.EmailAutomaticSend;
|
||||
txtEmailAutomaticSendTo.Text = Config.EmailAutomaticSendTo;
|
||||
|
||||
// SendSpace
|
||||
|
||||
|
@ -1671,11 +1673,6 @@ private void txtPassword_TextChanged(object sender, EventArgs e)
|
|||
Config.EmailPassword = txtEmailPassword.Text;
|
||||
}
|
||||
|
||||
private void chkEmailConfirm_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.EmailConfirmSend = cbEmailConfirm.Checked;
|
||||
}
|
||||
|
||||
private void cbRememberLastToEmail_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.EmailRememberLastTo = cbEmailRememberLastTo.Checked;
|
||||
|
@ -1691,6 +1688,17 @@ private void txtDefaultBody_TextChanged(object sender, EventArgs e)
|
|||
Config.EmailDefaultBody = txtEmailDefaultBody.Text;
|
||||
}
|
||||
|
||||
private void cbEmailAutomaticSend_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.EmailAutomaticSend = cbEmailAutomaticSend.Checked;
|
||||
txtEmailAutomaticSendTo.Enabled = Config.EmailAutomaticSend;
|
||||
}
|
||||
|
||||
private void txtEmailAutomaticSendTo_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.EmailAutomaticSendTo = txtEmailAutomaticSendTo.Text;
|
||||
}
|
||||
|
||||
#endregion Email
|
||||
|
||||
#region SendSpace
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -39,24 +39,45 @@ public override bool CheckConfig(UploadersConfig config)
|
|||
|
||||
public override void ShareURL(string url, UploadersConfig config)
|
||||
{
|
||||
using (EmailForm emailForm = new EmailForm(config.EmailRememberLastTo ? config.EmailLastTo : "", config.EmailDefaultSubject, url))
|
||||
if (config.EmailAutomaticSend && !string.IsNullOrEmpty(config.EmailAutomaticSendTo))
|
||||
{
|
||||
if (emailForm.ShowDialog() == DialogResult.OK)
|
||||
Email email = new Email()
|
||||
{
|
||||
if (config.EmailRememberLastTo)
|
||||
SmtpServer = config.EmailSmtpServer,
|
||||
SmtpPort = config.EmailSmtpPort,
|
||||
FromEmail = config.EmailFrom,
|
||||
Password = config.EmailPassword,
|
||||
ToEmail = config.EmailAutomaticSendTo,
|
||||
Subject = config.EmailDefaultSubject,
|
||||
Body = url
|
||||
};
|
||||
|
||||
email.Send();
|
||||
}
|
||||
else
|
||||
{
|
||||
using (EmailForm emailForm = new EmailForm(config.EmailRememberLastTo ? config.EmailLastTo : "", config.EmailDefaultSubject, url))
|
||||
{
|
||||
if (emailForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
config.EmailLastTo = emailForm.ToEmail;
|
||||
if (config.EmailRememberLastTo)
|
||||
{
|
||||
config.EmailLastTo = emailForm.ToEmail;
|
||||
}
|
||||
|
||||
Email email = new Email()
|
||||
{
|
||||
SmtpServer = config.EmailSmtpServer,
|
||||
SmtpPort = config.EmailSmtpPort,
|
||||
FromEmail = config.EmailFrom,
|
||||
Password = config.EmailPassword,
|
||||
ToEmail = emailForm.ToEmail,
|
||||
Subject = emailForm.Subject,
|
||||
Body = emailForm.Body
|
||||
};
|
||||
|
||||
email.Send();
|
||||
}
|
||||
|
||||
Email email = new Email
|
||||
{
|
||||
SmtpServer = config.EmailSmtpServer,
|
||||
SmtpPort = config.EmailSmtpPort,
|
||||
FromEmail = config.EmailFrom,
|
||||
Password = config.EmailPassword
|
||||
};
|
||||
|
||||
email.Send(emailForm.ToEmail, emailForm.Subject, emailForm.Body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,8 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
|||
public string EmailLastTo = "";
|
||||
public string EmailDefaultSubject = "Sending email from ShareX";
|
||||
public string EmailDefaultBody = "Screenshot is attached.";
|
||||
public bool EmailAutomaticSend = false;
|
||||
public string EmailAutomaticSendTo = "";
|
||||
|
||||
// Jira
|
||||
|
||||
|
|
Loading…
Reference in a new issue