예제 #1
0
 def __init__(self):
     self.client = PySendPulse(
         self.settings['api_id'],
         self.settings['api_secret'],
         # TOKEN_STORAGE,
         # memcached_host=MEMCACHED_HOST,
     )
예제 #2
0
def main():

    SENDPULSE_REST_API_ID = os.getenv('SENDPULSE_REST_API_ID', '')
    SENDPULSE_REST_API_SECRET = os.getenv('SENDPULSE_REST_API_SECRET', '')
    SENDPULSE_TOKEN_STORAGE = os.getenv('SENDPULSE_TOKEN_STORAGE', 'memcached')
    SENDPULSE_ADDRESSBOOK_ID = os.getenv('SENDPULSE_ADDRESSBOOK_ID', '')

    try:
        SPApiProxy = PySendPulse(SENDPULSE_REST_API_ID,
                                 SENDPULSE_REST_API_SECRET,
                                 SENDPULSE_TOKEN_STORAGE)
        emails_for_add = [{
            'email': '*****@*****.**',
            'variables': {
                'name': '232332',
                'number': '11'
            }
        }, {
            'email': '*****@*****.**'
        }, {
            'email': '*****@*****.**',
            'variables': {
                'firstname': 'test33',
                'age': 33,
                'date': '2015-09-30'
            }
        }]
        SPApiProxy.add_emails_to_addressbook(SENDPULSE_ADDRESSBOOK_ID,
                                             emails_for_add)
    except Exception as e:
        logger.exception(str(e))
예제 #3
0
 def report_error(self, reason, message):
     full_message = reason + ' ' + message
     subject = '[Checker Script Report]'
     email_temp = {
         'subject': '{0}'.format(subject),
         'html': '<p>' + full_message + '</p>',
         'text': full_message,
         'from': {
             'name': 'Anonymix',
             'email': '{0}'.format(self.sender_email)
         },
         'to': [{
             'name': 'User',
             'email': self.email
         }]
     }
     #input(email_temp)
     #sg = SendGridAPIClient(send_grid_api_key)
     s = PySendPulse(self.key, self.private)
     resp = s._PySendPulse__handle_result(
         s._PySendPulse__send_request('smtp/emails', 'POST',
                                      {'email': json.dumps(email_temp)}))
     if resp['result']:
         return True
     else:
         return False
예제 #4
0
class SendpulseEmailProvider(TemplatingMixin, BaseEmailProvider):
    settings = settings.MSGS['providers']['sendpulse']['options']

    def __init__(self):
        self.client = PySendPulse(
            self.settings['api_id'],
            self.settings['api_secret'],
            # TOKEN_STORAGE,
            # memcached_host=MEMCACHED_HOST,
        )

    def perform(self, message: AbstractMessage, sender: str, lang: str,
                **kwargs):
        context = self.get_context_data(message)
        title_html, body_html = self.render(message, lang, context)
        # attachments = self.get_attachments(message, lang, context)
        message_data = {
            'subject': title_html,
            'html': body_html,
            'text': self.html_to_text(body_html),
            'from': {
                'name': self.settings['sender_name'],
                'email': self.settings['sender'],
            },
            'to': [
                {
                    'name': '',
                    'email': message.recipient,
                },
            ],
        }
        response = self.client.smtp_send_mail(message_data)
        return response
예제 #5
0
def sp_send_simple_email(subject, html, text, to_name, to_email):
    EMAIL_REST_API_ID = os.environ['EMAIL_REST_API_ID']
    EMAIL_REST_API_SECRET = os.environ['EMAIL_REST_API_SECRET']
    EMAIL_TOKEN_STORAGE = os.environ['EMAIL_TOKEN_STORAGE']
    EMAIL_SENDER_NAME = os.environ['EMAIL_SENDER_NAME']
    EMAIL_SENDER_ID = os.environ['EMAIL_SENDER_ID']

    SPApiProxy = PySendPulse(EMAIL_REST_API_ID, EMAIL_REST_API_SECRET,
                             EMAIL_TOKEN_STORAGE)
    email = {
        'subject': subject,
        'html': html,
        'text': text,
        'from': {
            'name': EMAIL_SENDER_NAME,
            'email': EMAIL_SENDER_ID
        },
        'to': [{
            'name': to_name,
            'email': to_email
        }]
    }

    SPApiProxy.smtp_send_mail(email)
예제 #6
0
def send_mail(request):
	rescall = check_valid_call(request)
	if rescall:
		pass
	else:
		return HttpResponse(status=401)
	res = check_protection(request)
	if res:
		pass
	else:
		return redirect('/viewprotection')
	ckey = CaptchaStore.pick()
	pkey = pgp_public
	#print(keyy)
	url_c = captcha_image_url(ckey)
	if request.method == 'POST':

		email = request.POST.get('email','')
		subject = request.POST.get('subject','')
		idd = request.POST.get('session','')
		message = request.POST.get('bodyMessage','')
		captcha = request.POST.get('captcha','')
		#keyy = request.POST.get('token','')
		print(captcha)
		if email != '' and subject != '' and idd != '' and message != '' and captcha != '' :#and keyy != '':
			#resp_cont = CaptchaStore.objects.filter(hashkey = keyy)
			#print(len(resp_cont))
			#resp = resp_cont[0].response
			#print(resp)
			if captcha:

				pass
			else:
				return render(request,'contact.html',{'message':'captcha not valid','key':pkey,'link':url_c,'token':ckey})
			pre_message = "MIX ID :  {0} \nEMAIL  :  {1} \n".format(idd,email)
			message = pre_message + message
			sett = Settings.objects.all()[0]

			email_temp = {
				'subject':'{0}'.format(subject) ,
				'html': '<p>'+message+'</p>',
				'text': message,
				'from': {'name': 'Anonymix', 'email': '{0}'.format(sender_mail)},
				'to': [
					{'name': 'User', 'email': sett.support_mail}
				]
			}
			#input(email_temp)
			#sg = SendGridAPIClient(send_grid_api_key)
			s = PySendPulse(key,private)
			resp = s._PySendPulse__handle_result(s._PySendPulse__send_request('smtp/emails', 'POST', {'email': json.dumps(email_temp)}))
			if resp['result']:
				return render(request,'contact.html',{'message':'success','key':pkey,'link':url_c,'token':ckey})
			else:
				return render(request,'contact.html',{'message':'failed','key':pkey,'link':url_c,'token':ckey})

		else:
			return render(request,'contact.html',{'message':'failed','key':pkey,'link':url_c,'token':ckey})

	else:
		return render(request,'contact.html',{'message':'failed','key':pkey,'link':url_c,'token':ckey})
def main():

    SENDPULSE_REST_API_ID = os.getenv('SENDPULSE_REST_API_ID', '')
    SENDPULSE_REST_API_SECRET = os.getenv('SENDPULSE_REST_API_SECRET', '')
    SENDPULSE_TOKEN_STORAGE = os.getenv('SENDPULSE_TOKEN_STORAGE', 'memcached')
    SENDPULSE_CONTACT_INFO_ID = os.getenv('SENDPULSE_CONTACT_INFO_ID', '')

    MSSQL_DRIVER = os.getenv('MSSQL_DRIVER', '{FreeTDS}')
    MSSQL_TDS_VERSION = os.getenv('MSSQL_TDS_VERSION', 8.0)
    MSSQL_SERVER = os.getenv('MSSQL_SERVER')
    MSSQL_PORT = os.getenv('MSSQL_PORT', 1433)
    MSSQL_DATABASE = os.getenv('MSSQL_DATABASE')
    MSSQL_UID = os.getenv('MSSQL_UID')
    MSSQL_PWD = os.getenv('MSSQL_PWD')

    MSSQL_CONNECTION_STRING = 'DRIVER={DRIVER};' \
        'SERVER={SERVER};' \
        'PORT={PORT};' \
        'DATABASE={DATABASE};' \
        'UID={UID};' \
        'PWD={PWD};' \
        'TDS_Version={TDS_VERSION};'.format(
        DRIVER=MSSQL_DRIVER,
        TDS_VERSION=MSSQL_TDS_VERSION,
        SERVER=MSSQL_SERVER,
        PORT=MSSQL_PORT,
        DATABASE=MSSQL_DATABASE,
        UID=MSSQL_UID,
        PWD=MSSQL_PWD,
    )

    MSSQL_DATABASE_CONNECTION = pyodbc.connect(MSSQL_CONNECTION_STRING)
    # MSSQL_DATABASE_CONNECTION.setencoding('utf-8')

    MSSQL_DATABASE_CURSOR = MSSQL_DATABASE_CONNECTION.cursor()

    try:
        SPApiProxy = PySendPulse(SENDPULSE_REST_API_ID,
                                 SENDPULSE_REST_API_SECRET,
                                 SENDPULSE_TOKEN_STORAGE)

        with MSSQL_DATABASE_CONNECTION:
            MSSQL_DATABASE_CURSOR.execute("\
                SELECT DISTINCT [Дата создания] \
                  ,[Имя] \
                  ,[Номер] \
                  ,[Электронная почта] \
                  ,[Последняя встреча] \
                  ,[Последний звонок] \
                  ,[Название] \
                  ,[ContactTS] \
                FROM [a2profile_fh].[dbo].[tGetContactInfo] \
                WHERE [Электронная почта] IS NOT NULL AND [Электронная почта] != ''"
                                          )

            emails_for_add = []

            for row in MSSQL_DATABASE_CURSOR.fetchall():
                if row[0]:
                    created_at = row[0].strftime('%Y-%m-%d')
                else:
                    created_at = ''

                if row[1]:
                    first_name = row[1].split('-')[0].capitalize() or ''
                else:
                    first_name = ''

                number = row[2] or ''

                email = row[3] or ''

                if row[4]:
                    last_meeting = row[4].strftime('%Y-%m-%d')
                else:
                    last_meeting = ''

                if row[5]:
                    last_call = row[5].strftime('%Y-%m-%d')
                else:
                    last_call = ''

                name = row[6] or ''

                if email:
                    emails_for_add.append({
                        'email': email,
                        'variables': {
                            'created_at': created_at,
                            'first_name': first_name,
                            # 'number': number,
                            'last_meeting': last_meeting,
                            'last_call': last_call,
                            'name': name,
                        }
                    })

            SPApiProxy.add_emails_to_addressbook(SENDPULSE_CONTACT_INFO_ID,
                                                 emails_for_add)
    except Exception as e:
        logger.exception(str(e))
""" SendPulse REST API usage example

Documentation:
    https://login.sendpulse.com/manual/rest-api/
    https://sendpulse.com/api
"""

from pysendpulse.pysendpulse import PySendPulse

if __name__ == "__main__":
    REST_API_ID = ''
    REST_API_SECRET = ''
    TOKEN_STORAGE = 'memcached'
    MEMCACHED_HOST = '127.0.0.1:11211'
    SPApiProxy = PySendPulse(REST_API_ID, REST_API_SECRET, TOKEN_STORAGE, memcached_host=MEMCACHED_HOST)

    # Get list of tasks
    SPApiProxy.push_get_tasks()

    # Get list of websites
    SPApiProxy.push_get_websites()

    # Get amount of websites
    SPApiProxy.push_count_websites()

    # Get list of variables for website
    SPApiProxy.push_get_variables(WEBSITE_ID)

    # Get list of subscriptions for website
    SPApiProxy.push_get_subscriptions(WEBSITE_ID)
def main():

    SENDPULSE_REST_API_ID = os.getenv('SENDPULSE_REST_API_ID', '')
    SENDPULSE_REST_API_SECRET = os.getenv('SENDPULSE_REST_API_SECRET', '')
    SENDPULSE_TOKEN_STORAGE = os.getenv('SENDPULSE_TOKEN_STORAGE', 'memcached')
    SENDPULSE_CLIENT_INFO_ID = os.getenv('SENDPULSE_CLIENT_INFO_ID', '')

    MSSQL_DRIVER = os.getenv('MSSQL_DRIVER', '{FreeTDS}')
    MSSQL_TDS_VERSION = os.getenv('MSSQL_TDS_VERSION', 8.0)
    MSSQL_SERVER = os.getenv('MSSQL_SERVER')
    MSSQL_PORT = os.getenv('MSSQL_PORT', 1433)
    MSSQL_DATABASE = os.getenv('MSSQL_DATABASE')
    MSSQL_UID = os.getenv('MSSQL_UID')
    MSSQL_PWD = os.getenv('MSSQL_PWD')

    MSSQL_CONNECTION_STRING = 'DRIVER={DRIVER};' \
        'SERVER={SERVER};' \
        'PORT={PORT};' \
        'DATABASE={DATABASE};' \
        'UID={UID};' \
        'PWD={PWD};' \
        'TDS_Version={TDS_VERSION};'.format(
        DRIVER=MSSQL_DRIVER,
        TDS_VERSION=MSSQL_TDS_VERSION,
        SERVER=MSSQL_SERVER,
        PORT=MSSQL_PORT,
        DATABASE=MSSQL_DATABASE,
        UID=MSSQL_UID,
        PWD=MSSQL_PWD,
    )

    MSSQL_DATABASE_CONNECTION = pyodbc.connect(MSSQL_CONNECTION_STRING)
    # MSSQL_DATABASE_CONNECTION.setencoding('utf-8')

    MSSQL_DATABASE_CURSOR = MSSQL_DATABASE_CONNECTION.cursor()

    try:
        SPApiProxy = PySendPulse(SENDPULSE_REST_API_ID, SENDPULSE_REST_API_SECRET, SENDPULSE_TOKEN_STORAGE)

        with MSSQL_DATABASE_CONNECTION:
            MSSQL_DATABASE_CURSOR.execute("\
                SELECT DISTINCT [Номер анкеты] AS form_id \
                    ,[Дата создания] AS created_at \
                    ,[Фамилия] AS surname \
                    ,[Имя] AS first_name \
                    ,[Отчество] AS second_name \
                    ,[Дата рождения] AS birth_date \
                    ,[Пол.Название] AS sex \
                    ,[Электронная почта] AS email \
                    ,[Основной телефон.Номер] AS phone \
                    ,[Первый звонок] AS first_call \
                    ,[Последний звонок] AS last_call \
                    ,[Первая встреча] AS first_meeting \
                    ,[Последняя встреча] AS last_meeting \
                    ,[TS] AS ts \
                FROM [a2profile_fh].[dbo].[tGetClientInfo] \
                WHERE [Электронная почта] IS NOT NULL AND [Электронная почта] != ''"
            )

            emails_for_add = []

            for row in MSSQL_DATABASE_CURSOR.fetchall():
                form_id = row[0] or ''
                if row[1]:
                    created_at = row[1].strftime('%Y-%m-%d')
                else:
                    created_at = ''

                if row[2]:
                    surname = row[2].split('-')[0].capitalize() or ''
                else:
                    surname = ''

                if row[3]:
                    first_name = row[3].split('-')[0].capitalize() or ''
                else:
                    first_name = ''

                if row[4]:
                    second_name = row[4].split('-')[0].capitalize() or ''
                else:
                    second_name = ''

                if row[5]:
                    birth_date = row[5].strftime('%Y-%m-%d')
                else:
                    birth_date = ''

                sex = row[6] or ''
                email = row[7] or ''
                phone = row[8] or ''

                if row[9]:
                    first_call = row[9].strftime('%Y-%m-%d')
                else:
                    first_call = ''

                if row[10]:
                    last_call = row[10].strftime('%Y-%m-%d')
                else:
                    last_call = ''

                if row[11]:
                    first_meeting = row[11].strftime('%Y-%m-%d')
                else:
                    first_meeting = ''

                if row[12]:
                    last_meeting = row[12].strftime('%Y-%m-%d')
                else:
                    last_meeting = ''

                ts = row[13] or ''

                if email:
                    emails_for_add.append({
                        'email': email,
                        'variables': {
                            'phone': phone,
                            # 'form_id': form_id,
                            'created_at': created_at,
                            # 'surname': surname,
                            'first_name': first_name,
                            # 'second_name': second_name,
                            'birth_date': birth_date,
                            'sex': sex,
                            'first_call': first_call,
                            'last_call': last_call,
                            # 'first_meeting': first_meeting,
                            # 'last_meeting': last_meeting,
                        }
                    })

            SPApiProxy.add_emails_to_addressbook(SENDPULSE_CLIENT_INFO_ID, emails_for_add)
    except Exception as e:
        logger.exception(str(e))
# -*-coding:utf8-*-
""" SendPulse REST API usage example

Documentation:
    https://login.sendpulse.com/manual/rest-api/
    https://sendpulse.com/api
"""

from pysendpulse.pysendpulse import PySendPulse

if __name__ == "__main__":
    REST_API_ID = ''
    REST_API_SECRET = ''
    TOKEN_STORAGE = 'memcached'
    SPApiProxy = PySendPulse(REST_API_ID, REST_API_SECRET, TOKEN_STORAGE)

    # Get list of tasks
    SPApiProxy.push_get_tasks()

    # Get list of websites
    SPApiProxy.push_get_websites()

    # Get amount of websites
    SPApiProxy.push_count_websites()

    # Get list of variables for website
    SPApiProxy.push_get_variables(WEBSITE_ID)

    # Get list of subscriptions for website
    SPApiProxy.push_get_subscriptions(WEBSITE_ID)