mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Contact - Added SMTP config and sending of mail when Contact message sent
This commit is contained in:
parent
4c217b9c6d
commit
016df19d28
@ -3,10 +3,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Net.Mail;
|
||||
using Teknik.Controllers;
|
||||
using Teknik.Areas.Contact.ViewModels;
|
||||
using Teknik.Areas.Contact.Models;
|
||||
using Teknik.Models;
|
||||
using System.Text;
|
||||
|
||||
namespace Teknik.Areas.Contact.Controllers
|
||||
{
|
||||
@ -32,6 +34,36 @@ namespace Teknik.Areas.Contact.Controllers
|
||||
{
|
||||
if (model.Insert())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Let's also email the message to support
|
||||
SmtpClient client = new SmtpClient();
|
||||
client.Host = Config.SMTPConfig.Host;
|
||||
client.Port = Config.SMTPConfig.Port;
|
||||
client.EnableSsl = Config.SMTPConfig.SSL;
|
||||
client.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
client.UseDefaultCredentials = true;
|
||||
client.Credentials = new System.Net.NetworkCredential(Config.SMTPConfig.Username, Config.SMTPConfig.Password);
|
||||
client.Timeout = 5000;
|
||||
|
||||
MailMessage mail = new MailMessage(Config.SupportEmail, Config.SupportEmail);
|
||||
mail.Subject = string.Format("Support Message from: {0} <{1}>", model.Name, model.Email);
|
||||
mail.Body = string.Format(@"
|
||||
New Support Message from: {0} <{1}>
|
||||
|
||||
---------------------------------
|
||||
Subject: {2}
|
||||
Message: {3}", model.Name, model.Email, model.Subject, model.Message);
|
||||
mail.BodyEncoding = UTF8Encoding.UTF8;
|
||||
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
|
||||
|
||||
client.Send(mail);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { error = "Error submitting message. Exception: " + ex.Message});
|
||||
}
|
||||
|
||||
return Json(new { result = "true" });
|
||||
}
|
||||
return Json(new { error = "Error submitting message." });
|
||||
|
@ -68,7 +68,11 @@
|
||||
<form>
|
||||
<legend><span class="glyphicon glyphicon-globe"></span> Where to find us</legend>
|
||||
<address>
|
||||
<strong>/g/ Technology on IRC</strong><br>
|
||||
<strong>Teknik on Rizon IRC</strong><br>
|
||||
#Teknik (<a href="irc://irc.rizon.net" target="_blank">irc.rizon.net</a>)<br>
|
||||
</address>
|
||||
<address>
|
||||
<strong>/g/ Technology on Rizon IRC</strong><br>
|
||||
#/g/technology (<a href="irc://irc.rizon.net" target="_blank">irc.rizon.net</a>)<br>
|
||||
</address>
|
||||
<address>
|
||||
|
@ -12,19 +12,28 @@ namespace Teknik
|
||||
private ReaderWriterLockSlim _ConfigFileRWLock;
|
||||
private JsonSerializerSettings _JsonSettings;
|
||||
|
||||
private bool _DevEnvironment;
|
||||
private string _Title;
|
||||
private string _Description;
|
||||
private string _Author;
|
||||
private string _Host;
|
||||
private string _BitcoinAddress;
|
||||
private bool _DevEnvironment;
|
||||
private string _Title;
|
||||
private string _Description;
|
||||
private string _Author;
|
||||
private string _Host;
|
||||
private SMTPConfig _SMTPConfig;
|
||||
private string _SupportEmail;
|
||||
private string _BitcoinAddress;
|
||||
|
||||
public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
|
||||
public string Title { get { return _Title; } set { _Title = value; } }
|
||||
public string Description { get { return _Description; } set { _Description = value; } }
|
||||
public string Author { get { return _Author; } set { _Author = value; } }
|
||||
public string Host { get { return _Host; } set { _Host = value; } }
|
||||
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
|
||||
public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
|
||||
|
||||
public string Title { get { return _Title; } set { _Title = value; } }
|
||||
public string Description { get { return _Description; } set { _Description = value; } }
|
||||
public string Author { get { return _Author; } set { _Author = value; } }
|
||||
|
||||
public string Host { get { return _Host; } set { _Host = value; } }
|
||||
|
||||
public SMTPConfig SMTPConfig { get { return _SMTPConfig; } set { _SMTPConfig = value; } }
|
||||
|
||||
public string SupportEmail { get { return _SupportEmail; } set { _SupportEmail = value; } }
|
||||
|
||||
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
|
||||
|
||||
public Config()
|
||||
{
|
||||
@ -43,6 +52,8 @@ namespace Teknik
|
||||
Description = String.Empty;
|
||||
Author = String.Empty;
|
||||
Host = String.Empty;
|
||||
SMTPConfig = new SMTPConfig();
|
||||
SupportEmail = string.Empty;
|
||||
BitcoinAddress = string.Empty;
|
||||
}
|
||||
|
||||
|
32
Teknik/Configuration/SMTPConfig.cs
Normal file
32
Teknik/Configuration/SMTPConfig.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace Teknik
|
||||
{
|
||||
public class SMTPConfig
|
||||
{
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public bool SSL { get; set; }
|
||||
|
||||
public SMTPConfig()
|
||||
{
|
||||
SetDefaults();
|
||||
}
|
||||
|
||||
public void SetDefaults()
|
||||
{
|
||||
Host = string.Empty;
|
||||
Port = 25;
|
||||
Username = string.Empty;
|
||||
Password = string.Empty;
|
||||
SSL = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -155,6 +155,7 @@
|
||||
<Compile Include="Areas\Profile\ProfileAreaRegistration.cs" />
|
||||
<Compile Include="Configuration\Config.cs" />
|
||||
<Compile Include="Areas\Blog\Controllers\BlogController.cs" />
|
||||
<Compile Include="Configuration\SMTPConfig.cs" />
|
||||
<Compile Include="Controllers\DefaultController.cs" />
|
||||
<Compile Include="Areas\Dev\Controllers\DevController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
|
Loading…
Reference in New Issue
Block a user