2016-03-24 07:47:59 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2022-01-12 05:32:17 +13:00
|
|
|
|
Copyright (c) 2007-2022 ShareX Team
|
2016-03-24 07:47:59 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2016-03-23 15:45:12 +13:00
|
|
|
|
using ShareX.UploadersLib.FileUploaders;
|
2016-03-24 07:47:59 +13:00
|
|
|
|
using System.Windows.Forms;
|
2016-03-23 15:45:12 +13:00
|
|
|
|
|
|
|
|
|
namespace ShareX.UploadersLib.SharingServices
|
|
|
|
|
{
|
2016-03-24 07:47:59 +13:00
|
|
|
|
public class EmailSharingService : URLSharingService
|
2016-03-23 15:45:12 +13:00
|
|
|
|
{
|
|
|
|
|
public override URLSharingServices EnumValue { get; } = URLSharingServices.Email;
|
2016-03-24 07:47:59 +13:00
|
|
|
|
|
2016-03-23 15:45:12 +13:00
|
|
|
|
public override bool CheckConfig(UploadersConfig config)
|
|
|
|
|
{
|
2016-04-05 01:58:07 +12:00
|
|
|
|
return !string.IsNullOrEmpty(config.EmailSmtpServer) && config.EmailSmtpPort > 0 && !string.IsNullOrEmpty(config.EmailFrom) && !string.IsNullOrEmpty(config.EmailPassword);
|
2016-03-23 15:45:12 +13:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-10 22:55:21 +12:00
|
|
|
|
public override URLSharer CreateSharer(UploadersConfig config, TaskReferenceHelper taskInfo)
|
2016-03-23 15:45:12 +13:00
|
|
|
|
{
|
2017-09-10 22:55:21 +12:00
|
|
|
|
return new EmailSharer(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpEmail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class EmailSharer : URLSharer
|
|
|
|
|
{
|
|
|
|
|
private UploadersConfig config;
|
|
|
|
|
|
|
|
|
|
public EmailSharer(UploadersConfig config)
|
|
|
|
|
{
|
|
|
|
|
this.config = config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override UploadResult ShareURL(string url)
|
|
|
|
|
{
|
2017-09-11 00:29:29 +12:00
|
|
|
|
UploadResult result = new UploadResult { URL = url, IsURLExpected = false };
|
2017-09-10 22:55:21 +12:00
|
|
|
|
|
2016-05-25 06:50:26 +12:00
|
|
|
|
if (config.EmailAutomaticSend && !string.IsNullOrEmpty(config.EmailAutomaticSendTo))
|
2016-03-23 15:45:12 +13:00
|
|
|
|
{
|
2016-05-25 06:50:26 +12:00
|
|
|
|
Email email = new Email()
|
2016-03-23 15:45:12 +13:00
|
|
|
|
{
|
2016-05-25 06:50:26 +12:00
|
|
|
|
SmtpServer = config.EmailSmtpServer,
|
|
|
|
|
SmtpPort = config.EmailSmtpPort,
|
|
|
|
|
FromEmail = config.EmailFrom,
|
|
|
|
|
Password = config.EmailPassword,
|
|
|
|
|
ToEmail = config.EmailAutomaticSendTo,
|
|
|
|
|
Subject = config.EmailDefaultSubject,
|
|
|
|
|
Body = url
|
|
|
|
|
};
|
2016-03-23 15:45:12 +13:00
|
|
|
|
|
2016-05-25 06:50:26 +12:00
|
|
|
|
email.Send();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (EmailForm emailForm = new EmailForm(config.EmailRememberLastTo ? config.EmailLastTo : "", config.EmailDefaultSubject, url))
|
|
|
|
|
{
|
|
|
|
|
if (emailForm.ShowDialog() == DialogResult.OK)
|
2016-04-05 01:58:07 +12:00
|
|
|
|
{
|
2016-05-25 06:50:26 +12:00
|
|
|
|
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
|
|
|
|
|
};
|
2016-03-23 15:45:12 +13:00
|
|
|
|
|
2016-05-25 06:50:26 +12:00
|
|
|
|
email.Send();
|
|
|
|
|
}
|
2016-03-23 15:45:12 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-05 01:58:07 +12:00
|
|
|
|
|
|
|
|
|
//URLHelpers.OpenURL("mailto:?body=" + URLHelpers.URLEncode(url));
|
2016-05-01 20:27:39 +12:00
|
|
|
|
|
2017-09-10 22:55:21 +12:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2016-03-23 15:45:12 +13:00
|
|
|
|
}
|
|
|
|
|
}
|