コード例 #1
0
ファイル: mailer.py プロジェクト: TayebJa3ba/socialray
def sendInvite(html_filename, txt_filename, sender_account, subject, to_list, parameters):
    template_html = open(html_filename, 'r').read()
    template_text = open(txt_filename, 'r').read()    
    
    sender = '"' + sender_account.name + '" <' + sender_account.username + '*****@*****.**>'
    ext_html_message = replaceParams(template_html, parameters, sender_account)
    ext_text_message = replaceParams(template_text, parameters, sender_account)
    mailman.sendMail(sender, [to_list], subject, ext_html_message, text_message=ext_text_message,reply_to=sender_account.email)
    
コード例 #2
0
def handle(request, job_id):
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect('/login.htm')
    
    if not job_id:
        return siteaction.render_to_response('showmessage.htm', { 
                'msg_heading':'Error',
                'msg_html':'Access denied.'})
                
    job = dataplus.returnIfExists(models.JobPosition.objects.filter(id=job_id))
    if not job:
        return siteaction.render_to_response('showmessage.htm', { 
                'msg_heading':'Error',
                'msg_html':'Access denied.'})
    
    if job.posted_by:
        job.posted_by_name = job.posted_by.name
    elif job.tag:
        match = re.match('^.*name\=(?P<name>.*?);',job.tag)
        if match:
            job.posted_by_name = match.group('name')
        
    if request.method == 'GET':
        action_result = ''
        if dataplus.dictGetVal(request.REQUEST, 'flashId'):
            action_result = dataplus.dictGetVal(statix.action_messages, dataplus.dictGetVal(request.REQUEST, 'flashId'), '')
            
        if job.min_compensation == job.max_compensation:
            job.salary = str(job.min_compensation)
        else:
            job.salary = str(job.min_compensation) + ' - ' + str(job.max_compensation)
        return siteaction.render_to_response('jobs/viewjobposition.htm',
                            { 'myself': myself,
                              'job':job,
                              'action_result':action_result,
                            })
    elif request.method == 'POST':
        html_message = '<p>Hello ' + job.posted_by_name + ',</p><p>This is in reference to the job you posted titled "' + job.title + '" for ' + job.company_name + '. ' + \
                    'I would like to apply for this position and you can find my resume as an attachment.</p><p>You can always download my latest resume from ' + \
                    '<a href="' + config.server_base_url + config.profiles_url + '/' + myself.username + '">my profile</a>.</p>' + \
                    '<p>Regards,<br />' + myself.name + '</p><br /><br /><br /><br /><br /><br />'+ \
                    'Don\'t want to receive email alerts? Just change your <a href="' + config.server_base_url +  \
                    '/me/editsettings.htm">Email Forwarding Settings</a>'
                    
        text_message = 'Hello ' + job.posted_by_name + ',\r\nThis is in reference to the job you posted titled "' + job.title + '" for ' + job.company_name + '. ' + \
                    'I would like to apply for this position and you can find my resume as an attachment.\r\nYou can always download my latest resume from my profile at ' + \
                    config.server_base_url + config.profiles_url + '/' + myself.username + '.\r\n' + \
                    'Regards,\r\n' + myself.name + '\r\n\r\n\r\n\r\n\r\n\r\n' + + \
                    'Don\'t want to receive email alerts? Just change your Email Forwarding Settings, visit - "' +  \
                    config.server_base_url + '/me/editsettings.htm"'
                    
        resume_file = codejar_resume.getResumeFilePath(myself)
        mailman.sendMail('"' + myself.name + '" <' + myself.username + '*****@*****.**>', [job.contact_email], 'Re: Job Posting - ' + job.title, html_message, [resume_file], None, text_message, reply_to=myself.email)

        return HttpResponseRedirect('/jobs/' + str(job.id) + '/?flashId=resume_fwd')
コード例 #3
0
def handle(request): 
    try:
        myself = siteaction.getLoggedInUser(request)
        if not myself:
            return ajaxian.getFailureResp('not_logged_in')

        new_friend_id = dataplus.dictGetVal(request.REQUEST,'userId')
        new_friend = dataplus.returnIfExists(models.User.objects.filter(id=new_friend_id))
        if not new_friend:
            return ajaxian.getSuccessResp('user_not_exists')
            
        #surprise.... you cannot add yourself, as a friend too!
        if (str(myself.id) == new_friend_id):
            return ajaxian.getSuccessResp('cannot_add_yourself')        
        
        #see if such a friend exists
        #if so, then don't add
        friend = dataplus.returnIfExists(myself.friends.filter(id=new_friend_id))
        
        if not friend:
            #see if there is already a pending friend request
            #if a request exists from the other user lets make them friends
            friend_req_from = dataplus.returnIfExists(models.FriendRequest.objects.filter(sent_by__id=new_friend_id, sent_to__id=myself.id))
            if friend_req_from:
                myself.friends.add(new_friend)
                myself.save()
                friend_req_from.delete()    
                return ajaxian.getSuccessResp('friend_added')        
            
            #if a request from myself is there
            #if so don't add.. its pending
            friend_req_to = dataplus.returnIfExists(models.FriendRequest.objects.filter(sent_to__id=new_friend_id, sent_by__id=myself.id))
            if not friend_req_to:
                friend_req = models.FriendRequest()
                friend_req.sent_by = myself
                friend_req.sent_to = new_friend
                friend_req.sent_on = datetime.datetime.utcnow()
                friend_req.save()
                html_mail_content = '<p>Hello ' + new_friend.name + ',</p><p><a href="' + config.server_base_url + \
                    '/profiles/' + myself.username + '">' + myself.name + '</a> has sent you a friend request. Please <a href="http://www.socialray.org/me/">Login to Socialray</a> to approve or reject the request.</p>' + \
                    '<p>Regards,<br />from Socialray</p><br /><br /><br /><br /><br />' 
                        
                text_mail_content = 'Hello ' + new_friend.name + ',\r\n\r\n' + myself.name + '(' + config.server_base_url + \
                    '/profiles/' + myself.username + ') wants to be your friend. Please login to Socialray to approve or reject the request.\r\n\r\n' + \
                    'Regards,\r\nfrom Socialray\r\n\r\n\r\n\r\n\r\n' 
                    
                mailman.sendMail('"' + myself.name + '" <' + myself.username + '*****@*****.**>', [new_friend.email], 'Socialray: ' + myself.name + ' wants to add you as a friend', html_mail_content, None, None, text_mail_content, reply_to=myself.email)
                return ajaxian.getSuccessResp('request_added')
            else:
                return ajaxian.getSuccessResp('pending_request')
        else:
            return ajaxian.getSuccessResp('already_a_friend')
                
    except:
        return ajaxian.getFailureResp('unknown')        
コード例 #4
0
 def externalSender(rcvr_accounts):
     sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
     receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>' for rcvr in rcvr_accounts]
     ext_html_message = html_message + \
         '<br /><br /><br /><br /><br />' + \
         'If you don\'t want to receive notification emails, change your Account Settings ' + \
         '<a href="' + config.server_base_url + '/me/editsettings.htm">here</a>'                
     ext_text_message = text_message + \
         '\r\n\r\n\r\n\r\n\r\n' + \
         'If you don\'t want to receive notification emails, change your Account Settings here\r\n' + \
         config.server_base_url + '/me/editsettings.htm'
     mailman.sendMail(sender, receivers, subject, ext_html_message, None, None, ext_text_message, reply_to=myself.email)
コード例 #5
0
 def externalSender(rcvr_accounts):    
     sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
     receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]                
     ext_msg_to_admin_html = msg_to_admin_html + \
         '<br /><br /><br /><br /><br />' + \
         'If you don\'t want to receive notification emails, change your Account Settings ' + \
         '<a href="' + config.server_base_url + '/me/editsettings.htm">here</a>'                
     ext_msg_to_admin_text = msg_to_admin_text + \
         '\r\n\r\n\r\n\r\n\r\n' + \
         'If you don\'t want to receive notification emails, change your Account Settings here\r\n' + \
         config.server_base_url + '/me/editsettings.htm'                                
     mailman.sendMail(sender, receivers, 'Request to join ' + community.name, ext_msg_to_admin_html, 
         None, None, ext_msg_to_admin_text, reply_to=myself.email)
コード例 #6
0
def handle(request):
    myself = siteaction.getLoggedInUser(request)  
    if not myself:
        return HttpResponseRedirect('/login.htm?' + urllib.urlencode(
                {'returnUrl':'/me/viewreferral.htm?id=' + dataplus.dictGetVal(request.REQUEST, 'id', '')}))
    
    req_id = dataplus.dictGetVal(request.REQUEST, 'id', 0, string.atoi)
    if req_id > 0:
        referral = models.JobReferral.objects.get(id=req_id)
    
    if request.method == 'GET':
        action_result = ''
        if dataplus.dictGetVal(request.REQUEST, 'flashId'):
            action_result = dataplus.dictGetVal(statix.action_messages, dataplus.dictGetVal(request.REQUEST, 'flashId'), '')
        
        return siteaction.render_to_response('me/viewreferral.htm', 
                                    {'referral':referral,
                                    'action_result':action_result,
                                    'myself':myself})
    elif request.method == 'POST':
        html_message = '<p>Hi,</p><p>This is in reference to the job opening "' + referral.subject + '". ' + \
                    'I would like to apply for this position and you can find my resume as an attachment.</p><p>You can always download my latest resume from ' + \
                    '<a href="' + config.server_base_url + config.profiles_url + '/' + myself.username + '">my profile</a>.</p>' + \
                    '<p>Regards,<br />' + myself.name + '</p><br /><br /><br /><br /><br /><br />'+ \
                    'Don\'t want to receive email alerts? Just change your <a href="' + config.server_base_url +  \
                    '/me/editsettings.htm">Email Forwarding Settings</a>'
                    
        text_message = 'Hi,\r\nThis is in reference to the job opening "' + referral.subject + '". ' + \
                    'I would like to apply for this position and you can find my resume as an attachment.\r\nYou can always download my latest resume from my profile at ' + \
                    config.server_base_url + config.profiles_url + '/' + myself.username + '.\r\n' + \
                    'Regards,\r\n' + myself.name + '\r\n\r\n\r\n\r\n\r\n\r\n' + + \
                    'Don\'t want to receive email alerts? Just change your Email Forwarding Settings, visit - "' +  \
                    config.server_base_url + '/me/editsettings.htm"'   
                                    
        resume_file = codejar_resume.getResumeFilePath(myself)
        mailman.sendMail('"' + myself.name + '" <' + myself.username + '*****@*****.**>', [referral.reply_to_email], 'Re: Referral - ' + referral.subject, html_message, [resume_file], None, text_message, reply_to=myself.email)

        return HttpResponseRedirect('/me/viewreferral.htm?id=' + str(req_id) + '&amp;flashId=resume_fwd')
コード例 #7
0
 def externalSender(rcvr_accounts):
     sender = '"' + myself.name + '" <' + myself.username + '*****@*****.**>'
     receivers = ['"' + rcvr.name + '" <' + rcvr.email + '>'  for rcvr in rcvr_accounts]
     mailman.sendMail(sender, receivers, subject, html_message, 
         None, None, text_message, reply_to=myself.email)
コード例 #8
0
 def externalSender(rcvr_accounts):
     mailman.sendMail(
         sender_email, [user.email], subject, html_message, None, None, text_message, reply_to=user.email
     )
コード例 #9
0
def handle(request, comm_id):
    community = models.Community.objects.get(id=comm_id)
    community.image_url = dataplus.getStaticUrl(community.image_size3_file_path)
    myself = siteaction.getLoggedInUser(request)
    if not myself:
        return HttpResponseRedirect("/login.htm")

    if community.members.filter(id=myself.id).count() == 0:
        return siteaction.render_to_response(
            "me/showmessage.htm", {"myself": myself, "msg_heading": "Error", "msg_html": "Access denied"}
        )

    action = dataplus.dictGetVal(request.REQUEST, "action")

    if request.method == "GET":
        action_result = ""
        if dataplus.dictGetVal(request.REQUEST, "flashId"):
            action_result = dataplus.dictGetVal(
                statix.action_messages, dataplus.dictGetVal(request.REQUEST, "flashId"), ""
            )

        return siteaction.render_to_response(
            "communities/invite.htm",
            {
                "community": community,
                "friend_count": myself.friends.count(),
                "friends_html": getFriendsTable(myself, community),
                "invite_more": (action == "invite_more"),
                "action_result": action_result,
                "myself": myself,
            },
        )

    elif request.method == "POST":
        if action == "external_invite":
            message = dataplus.dictGetSafeVal(request.REQUEST, "msgToMembers", "")
            add_to_friend_list = dataplus.dictGetVal(request.REQUEST, "add_to_friend_list", False, lambda x: True)
            has_valid_emails = False

            for i in range(1, 6):
                email = dataplus.dictGetVal(request.REQUEST, "email" + str(i), "").strip()
                success, error = codejar_validation.validateEmail(email)

                if success:
                    has_valid_emails = True

                    invitation = models.FriendInvitation(sent_by=myself, sent_to_email=email)
                    invitation.invite_random_key = dataplus.getUniqueId()
                    invitation.save()

                    comm_invite = models.CommunityInvitation(sent_by=myself, community=community)
                    comm_invite.invite_random_key = invitation.invite_random_key
                    comm_invite.save()

                    sender = '"' + myself.name + '" <' + myself.username + "*****@*****.**>"
                    subject = myself.name + " has invited you to join " + community.name + " - Socialray"
                    if add_to_friend_list:
                        accept_url = (
                            config.server_base_url
                            + "/me/acceptinvite.htm?commFriendInviteId="
                            + str(invitation.invite_random_key)
                        )
                    else:
                        accept_url = (
                            config.server_base_url
                            + "/me/acceptinvite.htm?commInviteId="
                            + str(invitation.invite_random_key)
                        )

                    html_message = (
                        '<p><a href="'
                        + config.server_base_url
                        + "/profiles/"
                        + myself.username
                        + '">'
                        + myself.name
                        + "</a>"
                        + " feels that you will be interested in joining the "
                        + community.name
                        + " Community in Socialray and has sent you the following message:</p>"
                        + "<p>"
                        + dataplus.replaceHtmlLineBreaks(message)
                        + "</p>"
                        + '<p>To accept this invitation and create an account, visit <a href="'
                        + accept_url
                        + '">'
                        + accept_url
                        + "</a> "
                        + "<br />Once you create your account, "
                        + myself.name
                        + " will be connected to you as a friend.</p>"
                        + "<p>Regards,<br />from Socialray</p>"
                    )

                    text_message = (
                        myself.name
                        + " feels that you will be interested in joining the "
                        + community.name
                        + " Community in Socialray and has sent you the following message:\r\n"
                        + message
                        + "\r\n\r\n"
                        + "To accept this invitation and create an account, visit - "
                        + accept_url
                        + " \r\n"
                        + "Once you create your account, "
                        + myself.name
                        + " will be connected to you as a friend.\r\n"
                        + "You can check "
                        + myself.name
                        + "'s profile at "
                        + config.server_base_url
                        + "/profiles/"
                        + myself.username
                        + "\r\n\r\n"
                        + "Regards,\r\n"
                        + "from Socialray\r\n\r\n"
                    )

                    mailman.sendMail(
                        sender, [email], subject, html_message, None, None, text_message, reply_to=myself.email
                    )
            if not has_valid_emails:
                return siteaction.render_to_response(
                    "communities/invite.htm",
                    {
                        "community": community,
                        "friend_count": myself.friends.count(),
                        "friends_html": getFriendsTable(myself, community),
                        "myself": myself,
                    },
                )

        elif action == "internal_invite":
            message = dataplus.dictGetSafeVal(request.REQUEST, "msgToFriends", "")
            friend_count = dataplus.dictGetVal(request.REQUEST, "friendCount", 0, string.atoi)

            has_selected_users = False
            for i in range(1, friend_count + 1):
                chk_id = dataplus.dictGetVal(request.REQUEST, "checkbox" + str(i))
                if chk_id:
                    user = models.User.objects.get(id=chk_id)
                    has_selected_users = True
                    sendCommunityInvitationToUser(community, user, myself, message)

            if not has_selected_users:
                return siteaction.render_to_response(
                    "communities/invite.htm",
                    {
                        "community": community,
                        "friend_count": myself.friends.count(),
                        "friends_html": getFriendsTable(myself, community),
                        "myself": myself,
                    },
                )

        if community.is_moderated:
            flash_id = "mod_comm_invites_sent"
        else:
            flash_id = "comm_invites_sent"

        return HttpResponseRedirect(
            "/communities/" + str(community.id) + "/invite.htm?flashId=" + flash_id + "&amp;action=invite_more"
        )
コード例 #10
0
 def externalSender(rcvr_accounts):
     sender = '"' + myself.name + '" <' + myself.username + "*****@*****.**>"
     receivers = ['"' + rcvr.name + '" <' + rcvr.email + ">" for rcvr in rcvr_accounts]
     mailman.sendMail(
         sender, receivers, "A question for you!", html_message, None, None, text_message, reply_to=myself.email
     )