Django email verification - customize email html & 404 not found accounts/profile/ - django-allauth

I have two issues. Email verification works well, but I want to customize the email sent to users. Here is the content of the email:
Hello from Localhost!
You're receiving this e-mail because user test has given yours as an
e-mail address to connect their account.
To confirm this is correct, go to
http://127.0.0.1:8000/rest-auth/registration/account-confirm-email/MTE:1h4DCn:JtkrZ1wkENQIdG8ysIVu7Qx_R44/
Thank you from Localhost! https://localhost:8000/
How can I create an html file and fill in the content that I want to be sent in the email? And how about the email subject?
The second issue, is that when I click on the link, the user gets verrified, but then I get a 404 error on /accounts/profile.
Here is my code:
from allauth.account.views import confirm_email
urlpatterns = [
path('accounts/', include('allauth.urls')),
path('rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', confirm_email),
path('rest-auth/registration/', include('rest_auth.registration.urls')),
]
Do I have to add a url for accounts/profile/ and create an html template showing that the email verification was successful? Also, is there a way to change to url to i.e accounts/verification-success/?

Custom e-mail
You can find the default e-mail templates used here: https://github.com/pennersr/django-allauth/tree/master/allauth/templates/account/email
Subject: email_confirmation_subject.txt
Text e-mail: email_confirmation_message.txt
You can override them in your Django app like any other template.
To activate HTML, you just have to add your own file with the name email_confirmation_message.html.
You can also have different messages when you signup or just confirm an e-mail address.
You can have a look into the code to understand how it works.
accounts/profile/
When you end up here you have successfully logged in. However, you will need to implement a view for this URL yourself, as whatever is to be displayed here is project specific. You can also decide to redirect elsewhere:
https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url
From https://django-allauth.readthedocs.io/en/latest/faq.html#when-i-attempt-to-login-i-run-into-a-404-on-accounts-profile
Since you have to implement the profile yourself, you can use accounts/verification-success/, too.

Related

Can you upload a file to the Slack API using files.upload as a different user?

I'm trying to find a way to have an application post a text snippet to our support channel through the Slack API. Using the files.upload method, I can create a text snippet and share it with the channel, but the post appears to come from me (because the token used to authenticate the request is mine).
I'm looking for a way to do this, but make it appear with a custom user name and icon, like you can with the chat.postMessage method's username and icon_url parameters. Is there a way to achieve this?
There are two ways.
Way 1. - If you only want to upload in a channel and don't need to listen to any conversation, then you can use incoming-webhooks. And then override the username and icon. Read "Customizing your username and icon" in Here.
Way 2 - You can create a bot user and let the bot user type post this message for you. I guess right now you are using test tokens generated by Slack so you are getting your name only. But if you use bot-user then you can use custom Name and icon_url for your bot.
I hope this answers your question.
Yes, as #Abhinav Rai suggested, you need have bot. Slack support just answered me the same question.
To upload files as a bot you'll need to create an associated 'bot user' and post the file using the bot's token: https://api.slack.com/bot-users — all files must be owned by a user account and the bot user will fill this requirement.
There is a way 3 which uses the username function from chat.postMessage function. Follow this -
import slack
import json
import os
def pureimg(data1):
data1 = '[{"text": "", "image_url": "'+data1+'"}]'
data1 = [json.loads(data1[1:-1])]
return data1
#This function will make the image url to correct format.
slacker = slack.WebClient(token='your-token-here')
payoff=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'filename.png')
#It gives cross OS compatibility on filepath.
response=slacker.files_upload(channel='#theta',file=payoff)
payoff=response['file']['permalink']
#First We upload the local file to Slack and fetch permalink.
#If you do not have any local file just put the external image URL in the payoff.
response=slacker.chat_postMessage(channel='#channel_name', text="Sample Text", username='Bot name', attachments=pureimg(payoff), icon_emoji=':emoji:')
#Then, We post to Slack Channel as a bot!

What is the purpose of each parameter in a MailChimp unsubscribe URL?

In the following URL, that unsubscribes a user from a list:
http://xxxxx.us2.list-manage.com/unsubscribe?
u=87f537bccxx35e53a1890e0d9&
id=40dcxx6cd6&
e=c4aaxx1dd6&
c=9a6xx11963
What does each parameter do?
Today I had to learn what each nondescript parameter means so that I could generate URLs for each email I send through Mandrill. It wasn't that easy to discover their meaning, but here are the one's I've come up with and how I found out what they are.
http://xxxxx.us2.list-manage.com/unsubscribe?
u=87f537bccxx35e53a1890e0d9&
id=40dcxx6cd6&
e=c4aaxx1dd6&
c=9a6xx11963
URL format:
Protocol can be http or https.
Your username comes next
In the example, us2 is the MailChimp datacenter where your account resides. That's different for each account. (https://apidocs.mailchimp.com/api/2.0/) It's good practice to specify a DC even though the documentation says that it isn't required. Specifying it will cut down on unnecessary latency.
list-manage[n].com can work with or without the number at the end of the domain, or it can have a 1 or a 2. Changing that doesn't appear to matter, but I think it has something to do with their load balancing.
/unsubscribe can also be /subscribe or /profile (The latter appears to be dependent on the "e" parameter. (See below) When you don't specify it, it states, "List member profiles cannot be updated from test campaigns or archive pages" and if you specify an invalid value, you get an error page.
u Is a unique identifier for your account. Every list on your account uses it. (See http://kb.mailchimp.com/lists/signup-forms/find-the-unsubscribe-link-for-your-list for how you can view the various URLs for your account.)
id is your list ID
e is the euid as documented on https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
c I haven't seen this one yet, but my guess is that it's the campaign ID.
Also, when you wish to prefill subscribe and unsubscribe forms, you can use the following GET params.
EMAIL Allows you to enter the subscriber's email
MERGE1 Allows you to enter the subscriber's first name
MERGE2 Allows you to enter the subscriber's last name

Using Ruby/rails variables in a mandrill template

Is it possible to use your rails variables on a Mandrill template?
I have an app where a user gets notified via email on certain actions, and right now it's done with action mailer without using Mandrill so it's just a text email with no styling. Obviously, I'd prefer to use a mandrill template I already have to add some dynamic content via variables.. I see a ton of companies using variables in email notifications so i assume it's possible, i just haven't found many useful articles that explain how it's done. If you can point me towards a useful article or just answer the question it'd be really helpful! Right now, I already made the template using Mailchimp, then sent it to mandrill and it's ready for use. My app already has the Mandrill configurations and works properly (i use it for static email that don't include variables). All i really need to do is configure it to allow me to use variables.
Thanks in advance. Happy holidays and war eagle!
One way is to use the merge tags in the Mandrill template, and then either global_merge_vars (all recipients) or merge_vars (per recipients) message options to populate the template.
It is not very exciting approach, but it works fine.
In short, the solution is to put tags like:
*|MYTAG|*
anywhere in the template. Then, the send calls just need to populate the right option. Here for all participants:
mandrill = Mandrill::API.new('my_api_key')
template_name = "my-template-name"
template_content = [] # See doc, not related to the issue at hand.
message = {
to: [{email: 'smith#example.com'}],
headers: {"Reply-To" => "noreply#example.com"},
merge: true,
global_merge_vars: [
{name: 'mytag', content: "Hello, World"}
]
}
mandrill.messages.send_template(template_name, template_content, message)
This should send an email with the tag replaced with the corresponding contents (Hello, World here).

Can I filter Jira Issues that were created via a mail handler?

I'm hoping to create a report that will return all of the Issues that were created via a mail handler that we have set up.
I thought about trying to use "reporter=" in the JQL, but that only works in the cases for when the user isn't already in our system (we've set createuser=false).
I'm running 5.2.5, not-OnDemand.
You could work around this by having the mail handler add a unique tag to each issue that it creates, and then just filter on the tag.
First, create a custom field called "By Email".
than, using Script Runner, add the following script to the workflow, to the create transition:
from com.atlassian.jira import ComponentManager
cfm = ComponentManager.getInstance().getCustomFieldManager()
# read issue description
description = issue.getDescription()
if (description is not None) and ('Created via e-mail received from' in description):
issue.setCustomFieldValue(cfm.getCustomFieldObjectsByName("By Email"),'By Email')
this will add 'By Email' to all issues created by emails. Than, you can find those issues using the following JQL:
"By Email" is not EMPTY
Let me know if you're having truble implelenting this solution.
NOTE: If the email is sent from an email known to Jira (Jira's user) the sender will be set as the autor of the ticket and his email will not be saved.

Salesforce Create Buttons and Links option - Custom URL to launch email template

I have an email template that I would like to launch from within the case using a Link/Button. I see the option under setup->customize->cases->button and links I even see where I need to place the URL. What I don't see is nay documentation on how to build the URL to launch an email template. Any help you be great
I don't know if this is documented anywhere by salesforce, but I found from some guess work:
/_ui/core/email/author/EmailAuthor?p3_lkid={!Case.Id}&p2_lkid={!Case.ContactId}&template_id=00X40000000weWn
Just use that as the url content of a custom button or link. This one is for cases, as you are trying to do, but I think this should work for other types of objects as well.
The parameters are p3_lkid, which is the case id, p2_lkid which is the id of the contact you are emailing, and template_id which is hardcoded to the desired email template. (You can find this id by looking in the url of the Setup page for the template)
This was really helpful. I did, however, figure out another way to do it. Click on the "Send an Email" button you currently have. Copy the URL and add &template_id=YOUR TEMPLATE ID.
There is one other ID number that will show up in the original URL. Change that to be the dynamic field you want it to be.
For example:
Copy url from "Send Email": https://na3.salesforce.com/_ui/core/email/author/EmailAuthor?p3_lkid=70150000000Axj1&retURL=%2F70150000000Axj1
Add &template_id=YOUR TEMPLATE ID so it looks like this:
/_ui/core/email/author/EmailAuthor?p3_lkid=70150000000Axj1&retURL=%2F70150000000Axj1&template_id=YOUR TEMPLATE ID
Remove the other id (it's the object you used to send the email - so in this case, I was wanting to be able to send an email directly from a Campaign) and replace with the dynamic field:
/_ui/core/email/author/EmailAuthor?p3_lkid={!Campaign.Id}&retURL=%2F70150000000Axih&template_id=YOUR TEMPLATE ID
And voila! It should work!
Abeyer's answer is good. However, if the template contains solution attachments "{!Case.Solution_Attachments}" the attachments will not get included unless you add the new_template=1 parameter to the URL making it:
/_ui/core/email/author/EmailAuthor?p3_lkid={!Case.Id}&p2_lkid={!Case.ContactId}&template_id=00X40000000weWn&new_template=1

Resources