Django 2 email unsubscribe link - python-3.6

I want to add an unsubscribe link in emails being sent to the user. I am unsure on how to achieve it. I want the user to be able to unsubscribe without having to log in. Any suggestions on how to achieve this would be appreciated. Thanks

I'll assume you know how to send an email with django, and other basic things.
For every email you send to them, you have to build the unsubscribe link first, like the following. Note that the following has a url pattern, and a model that takes a uuid field (uuid4 to be specific, because it's the safest one). The reason why you want to do it this way is so random people can't go to YourWebsite.com/unsub_email/1, /2, /3, /4, etc, and unsub as many people as they possibly can by guessing the number. By doing it the way I show, there's something like a chance of 1 in 100, with like 50+ zero's after it that they would even get 1. So it's safer.
def send_user_an_email(id_of_your_object):
users_email = UsersEmail.objects.get(id=id_of_your_object)
unsub_link = 'https://www.YourWebsite.com/unsub_email/{}/{}/'.format(users_email.id, users_email.random_uuid)
subject = 'Your subject line.'
message = 'Your message body.\n\nGo here to unsubscribe: {}'.format(unsub_link)
mail_sent = send_mail(subject, message, 'DoNotReply#YourWebsite.com', [users_email.users_email_char_field])
return mail_sent
Then you just write a function to let them click a button on that page, and they get unsubbed, or however else you want to do it. An even safer option would be to show them a valid unsub page, but make them type out their email again, but don't show them the email related to the valid url pattern. That extra step would make it that much harder for someone who'd want to write a bad script to unsub everyone on your list.

Related

Telegram: How to find Group Chat ID?

I've been trying to solve this for three days and none pf the solutions I've found online seem to work, so I am going to have to ask for help.
I want to create a Telegram "Group Chat" to be used by members of a club I'm in. I created the chat named with the initials of the club, like: "ABCD" and added some members. Now I want to automate the sending of occasional messages to the group for all members to see. Weather forecast, random photograph from our gallery, etc.
Using #BotFather I created a bot called "ABCDbot" and noted the token for that bot. Now I have two "ABCD"s on my browser left side-panel. Selecting one gives me "ABCD bot" and selecting the other gives me "ABCD 123 members".
Using a perl script and LWP I can send a photo using
#!/usr/bin/perl -w
use feature 'say';
use LWP;
my $api = LWP::UserAgent->new ();
my $chat_id = '1234567890';
my $photo = '/home/user/gallery/photo999.jpg';
my $response = $api->post(
"https://api.telegram.org/bot<ABCDbot's token>/sendPhoto",
[ 'chat_id' => $chat_id,
'caption' => 'Photo Randomly Selected by the gallery',
'photo' => $photo,
],
'Content_Type' => 'form-data',
);
if ($response->is_success) {
say "Response..... Success!";
} else {
say "Response..... Failure!";
}
This works, providing I give it a legitimate chat_id and a legitimate file to send.
But the trouble is: I can't find the chat_id for the group chat with 123 members! Every method I've tried now proves to be obsolete or simply doesn't return the desired chat_id for the ABCD group chat. I can get my own chat ID or that of individual members of the group, or of the bot itself, and can successfully send photos, messages, etc to those destinations, but I just can't send anything to the group.
Can anybody walk me through the process of getting the chat_id for my group chat? Or direct me to a document describing an up-to-date, working method for obtaining same?
Assistance much appreciated.
Method 1 (WebZ)
This is based on JayeshRocks's question with some extra steps to make the ID work with Bot API. Thanks to him first.
Login to Telegram WebZ.
Open the chat you want to get its ID.
Your browser's address should look like https://web.telegram.org/z/#-1527776602.
Remove the protocol, domain and path keeping the anchor so your result looks like #-1527776602.
Replace "#-" with "-100" so it looks like -1001527776602.
You can now use your final result which should look like -1001527776602.
Method 2 (Private Supergroups)
If the chat is a private channel/supergroup, you can do the following:
Copy a link of a message. (It will look like https://t.me/c/1527776602/1002.)
Remove the protocol and domain name, so it looks like c/1527776602/1002.
Remove the first and last path, so it looks like 1527776602.
Append "-100" to the beginning of the result, so it looks like -1001527776602.
You can now use your final result which looks like -1001527776602.
Method 3 (Third-Party Bots)
If you trust 3rd party bots, there are many of them. A known one is #MissRose_bot which you can add it to your group and use its /id command. Another one is #usinfobot which works inline and only for public chats.
To get a telegram group ID you need to open the group on https://web.telegram.org/z/ when you do so click on the group you want to gain the ID of then if you look at the URL it will say something like https://web.telegram.org/z/#-1234567 and the numbers there is the ID of the telegram group!
Hope this helps

How can I get the input value of a text field that has been created with airtable in wordpress?

I am trying to make some further adjustments to an address text field. But the problem is that its made with airtable. I want to get the input of that address and use it to get some data from zillow API for the user. How can I do this? I have viewed the source HTML and I only see the airtable script.
This probably went unanswered for being too vague. I'll try to leave some pointers if anyone stumbles upon this in the future.
Are you the host of the WP page? do you have access to the Airtable base in question? Is the "frontend" viewable? Airtable's API is pretty well-documented, simple as it may be. Whatever you need, if it's from a shared view, it can be fetched with a curl request.
Other than that,if the base is public, or shared publicly, and particularly if you need this data at a steady rate or in larger quantities, you'd be better off requesting access and collecting the information with a script from the Scripting app. Since ES6, this is as trivial as doing something like
let query = await base.getTable
(cursor.activeTableId)
.selectRecordsAsync()
let payload, selectAll = query.records.map(rec => rec.name),
selectAll ?
payload = { records: JSON.stringify(selectAll) }
: console.error('something went wrong')
remoteFetchAsync(('your scraping endpoint', payload)=>
//rock'n'roll past this point
})

Shopware5 order confirmation email event

After a long investigation, I am not able to find the correct event to use JUST before the order confirmation email is sent.
I need to add a value in the s_order_attributes table which will be included in the email template.
I tried many events (e.g. checkout) but they are all triggered after the email ones.
thanks !
Looking at the code when the email is sent I assume there are two events you can try. You can either try Shopware_Modules_Order_SendMail_FilterVariables or sOrder::sendMail::before. These are executed right before the sending. If the attributes are not loaded from the database anymore in that moment you can set the public variables in sOrder to change the values that get into the mail. This might help you out as well but I prefer the FilterVariables event as it gives you direct access to the variables.

Create topic using a bot

I'm in a situation in which i need to be able to create a topics using self created bot. My forum has a special category and user, which can create a topics in that category.
Technology i'm using to create that bot is ruby + mechanize gem but it's not important right now. That bot works in a following way:
Sign in as previously mentioned user:
visit - /ucp.php?mode=login
fill the sign-in form using user credentials
if, after submiting a form, there is a sign-out link somewhere on the page, threat this whole process as "successfull"
Create a topic
visit - /posting.php?mode=post&f=21
fill subject field with desired subject
fill message field with desired message
submit a form using Submit button
And now, while first point works just great, the second one behaves in a strange way. After submiting a form, there is no error message or anything like that, i'm just getting redirected to /viewforum.php?f=21 (log's says that it's 302 Moved Temporarily status) page and the topic is not there.
Can anyone tell me what such behaviour means? Is there any security mechanism i don't know about? Please also note that the new topic form has form_token and creation_time fields filled correctly while form is beeing submited.
Thanks in advance for any clues.
According to this thread: https://stackoverflow.com/a/11713867/552936, user is treated as a bot if he sends a form without any delay (and it end's up with a 302 redirect). I can't find any info on google what's the exact delay, carck3r says that it's 8 seconds but for me, it was 2 seconds.

Wordpress Plug-in - Trigger e-mail based on a specific date

I currently have a registration form for people to signup and pick a date for an "appointment". They get sent an e-mail right after filling it up with the details. I need another e-mail to be sent a day before their chosen date to remind them, but that can't be fulfilled by plugins I currently have.
Does anyone know of any Wordpress plug-in that allows the sending of an e-mail message (with a template and user specific data) based on a specified date?
Any piece of information or advice would be highly appreciated. Thanks!
How I would approach this would be with Wordpresses event scheduling. When a user submits the form to schedule their appointment, set a new action for the reminder email:
// Set this when you send the confirmation email
// Set the $unix_timestamp to be whenever you want the reminder to be sent.
// Args can be an array of the data you will need. Such as the users email/appt date
$args = array(
'email' => 'email#email.com'
);
wp_schedule_single_event($unix_timestamp, 'set_reminder', $args);
Now we have to catch that, and create a function to actually create and send the email (assuming you use a similar process):
add_action('set_reminder','do_reminder');
function do_reminder($args) {
// $email = $args['email'], etc.
// send reminder email.
}
I recommend Wysija Newsletters. You http://wordpress.org/extend/plugins/wysija-newsletters/. You can use template and user specific data in your email with this plugin.
If you are comfortable with writing your own code(I guess you are more or less ok with that), you can use the WordPress Schedule API(okay, maybe that's not the official name, but it works). Basically it's kind of a cron-job, but for WordPress. It has one downside though - it will only trigger on time, if WordPress is rendered(in other words accessed, so that it's code will execute). That can be easily fixed by adding a simple cron-job to your hosting account, that will simply access your home page every X hours.
You can find useful information on the API here.
Basically what you should have inside of your scheduled function is to get the records of people that should be sent reminder emails(you should probably store additional information about whether a reminder email has been sent or not) and send them the emails. I don't know what is the way you're storing the information from the registration form, but if you are using a Custom Post Type, then things should be pretty easy for you.

Resources