Bug fixes to Email Marketing

This commit is contained in:
usmannasir
2018-10-19 22:47:15 +05:00
parent 001f762d9d
commit 7165433989
12 changed files with 1407 additions and 27 deletions

View File

@@ -554,6 +554,7 @@
<li><a href="{% url 'emailPolicyServer' %}" title="{% trans 'Email Policy Server' %}"><span>{% trans "Email Policy Server" %}</span></a></li>
<li><a href="{% url 'listDomains' %}" title="{% trans 'Email Limits' %}"><span>{% trans "Email Limits" %}</span></a></li>
<li><a href="{% url 'SpamAssassin' %}" title="{% trans 'SpamAssassin Configurations' %}"><span>{% trans "SpamAssassin" %}</span></a></li>
<li><a href="{% url 'emailMarketing' %}" title="{% trans 'Email Marketing' %}"><span>{% trans "Email Marketing" %}</span></a></li>
</ul>
</div><!-- .sidebar-submenu -->

View File

@@ -43,17 +43,21 @@ class emailMarketing(multi.Thread):
with open(self.extraArgs['path'], 'r') as emailsList:
data = csv.reader(emailsList, delimiter=',')
for items in data:
for value in items:
if re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', value) != None:
try:
getEmail = EmailsInList.objects.get(owner=newList, email=value)
except:
newEmail = EmailsInList(owner=newList, email=value,
verificationStatus='NOT CHECKED',
dateCreated=time.strftime("%I-%M-%S-%a-%b-%Y"))
newEmail.save()
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], str(counter) + ' emails read.')
counter = counter + 1
try:
for value in items:
if re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', value) != None:
try:
getEmail = EmailsInList.objects.get(owner=newList, email=value)
except:
newEmail = EmailsInList(owner=newList, email=value,
verificationStatus='NOT CHECKED',
dateCreated=time.strftime("%I-%M-%S-%a-%b-%Y"))
newEmail.save()
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'], str(counter) + ' emails read.')
counter = counter + 1
except BaseException, msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
continue
elif self.extraArgs['path'].endswith('.txt'):
with open(self.extraArgs['path'], 'r') as emailsList:
emails = emailsList.readline()
@@ -137,13 +141,14 @@ class emailMarketing(multi.Thread):
domain = verificationList.owner.domain
tempStatusPath = '/home/cyberpanel/' + domain + "/" + self.extraArgs['listName']
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, str(msg) +'. [404]')
logging.CyberCPLogFileWriter.writeToFile('your error')
return 0
def startEmailJob(self):
try:
try:
if self.extraArgs['host'] == 'localhost':
smtpServer = smtplib.SMTP(self.extraArgs['host'])
smtpServer = smtplib.SMTP('127.0.0.1')
else:
verifyHost = SMTPHosts.objects.get(host=self.extraArgs['host'])
smtpServer = smtplib.SMTP(verifyHost.host, int(verifyHost.port))
@@ -169,6 +174,11 @@ class emailMarketing(multi.Thread):
sent = 0
failed = 0
ipFile = "/etc/cyberpanel/machineIP"
f = open(ipFile)
ipData = f.read()
ipAddress = ipData.split('\n', 1)[0]
## Compose Message
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@@ -178,17 +188,34 @@ class emailMarketing(multi.Thread):
message['Subject'] = emailMessage.subject
message['From'] = emailMessage.fromEmail
if re.search('<html>', emailMessage.emailMessage, re.IGNORECASE):
html = MIMEText(emailMessage.emailMessage, 'html')
message.attach(html)
else:
html = MIMEText(emailMessage.emailMessage, 'plain')
message.attach(html)
for items in allEmails:
if items.verificationStatus == 'Verified' or self.extraArgs['verificationCheck']:
if (items.verificationStatus == 'Verified' or self.extraArgs['verificationCheck']) and not items.verificationStatus == 'REMOVED':
try:
if re.search('<html>', emailMessage.emailMessage, re.IGNORECASE):
html = MIMEText(emailMessage.emailMessage, 'html')
message.attach(html)
if self.extraArgs['unsubscribeCheck']:
removalMessage = '<br><br><a href="https://' + ipAddress + ':8090/emailMarketing/remove/' + \
self.extraArgs[
'listName'] + "/" + items.email + '">Unsubscribe from future emails.</a>'
additionalCheck = MIMEText(removalMessage, 'html')
message.attach(additionalCheck)
else:
html = MIMEText(emailMessage.emailMessage, 'plain')
message.attach(html)
if self.extraArgs['unsubscribeCheck']:
finalMessage = '\n\n Unsubscribe by visiting https://' + ipAddress + ':8090/emailMarketing/remove/' + \
self.extraArgs[
'listName'] + "/" + items.email
html = MIMEText(finalMessage, 'plain')
message.attach(html)
smtpServer.sendmail(message['From'], items.email, message.as_string())
sent = sent + 1
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
@@ -198,6 +225,7 @@ class emailMarketing(multi.Thread):
logging.CyberCPLogFileWriter.statusWriter(self.extraArgs['tempStatusPath'],
'Successfully sent: ' + str(
sent) + ', Failed: ' + str(failed))
logging.CyberCPLogFileWriter.writeToFile(str(msg))
emailJob = EmailJobs(owner=emailMessage, date=time.strftime("%I-%M-%S-%a-%b-%Y"),

View File

@@ -662,8 +662,15 @@ class EmailMarketingManager:
extraArgs['selectedTemplate'] = data['selectedTemplate']
extraArgs['listName'] = data['listName']
extraArgs['host'] = data['host']
extraArgs['verificationCheck'] = data['verificationCheck']
extraArgs['unsubscribeCheck'] = data['unsubscribeCheck']
try:
extraArgs['verificationCheck'] = data['verificationCheck']
except:
extraArgs['verificationCheck'] = False
try:
extraArgs['unsubscribeCheck'] = data['unsubscribeCheck']
except:
extraArgs['unsubscribeCheck'] = False
extraArgs['tempStatusPath'] = "/home/cyberpanel/" + data['selectedTemplate'] + '_pendingJob'
currentACL = ACLManager.loadedACL(userID)
@@ -730,4 +737,16 @@ class EmailMarketingManager:
except BaseException, msg:
final_dic = {'status': 0, 'error_message': str(msg)}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
return HttpResponse(final_json)
def remove(self, listName, emailAddress):
try:
eList = EmailLists.objects.get(listName=listName)
removeEmail = EmailsInList.objects.get(owner=eList, email=emailAddress)
removeEmail.verificationStatus = 'REMOVED'
removeEmail.save()
except:
pass
return HttpResponse('Email Address Successfully removed from the list.')

View File

@@ -23,4 +23,5 @@ urlpatterns = [
url(r'^startEmailJob$', views.startEmailJob, name='startEmailJob'),
url(r'^deleteTemplate$', views.deleteTemplate, name='deleteTemplate'),
url(r'^deleteJob$', views.deleteJob, name='deleteJob'),
url(r'^remove/(?P<listName>[-\w]+)/(?P<emailAddress>\w+@.+)$', views.remove, name='remove'),
]

View File

@@ -179,5 +179,13 @@ def deleteJob(request):
userID = request.session['userID']
emm = EmailMarketingManager(request)
return emm.deleteJob()
except KeyError:
return redirect(loadLoginPage)
def remove(request, listName, emailAddress):
try:
emm = EmailMarketingManager(request)
return emm.remove(listName, emailAddress)
except KeyError:
return redirect(loadLoginPage)

View File

@@ -687,8 +687,8 @@ class preFlightsChecks:
count = 0
while (1):
#command = "wget http://cyberpanel.net/CyberPanel.1.7.2.tar.gz"
command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz"
command = "wget http://cyberpanel.net/CyberPanel.1.7.2.tar.gz"
#command = "wget http://cyberpanel.net/CyberPanelTemp.tar.gz"
res = subprocess.call(shlex.split(command))
if res == 1:
@@ -707,8 +707,8 @@ class preFlightsChecks:
count = 0
while(1):
#command = "tar zxf CyberPanel.1.7.2.tar.gz"
command = "tar zxf CyberPanelTemp.tar.gz"
command = "tar zxf CyberPanel.1.7.2.tar.gz"
#command = "tar zxf CyberPanelTemp.tar.gz"
res = subprocess.call(shlex.split(command))

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB