hMailServer sending limit per day - spam-prevention

I want to set a max number of email sent a day for each mailbox on hmailserver to avoid spamming.
I am looking for an issue to do this in hmailserver administration and COM API.

I believe there's no such property in hMailServer. You must define a script on OnAcceptMessage event to implement this behaviour hMailserve doc | OnAcceptMessage.
For the number of emails sent per day you must create some kind of counter (a database table with username, date and count fields) and get the current number of messages in the body of the OnAcceptMessage function. If the count per current user and current day will be reached then reject the email with return code 1 or 2 and a meaningful message. If the count is less return 0 and the email will be sent.

Related

Generate Sequential Application number

I have a requirement where I need to generate Unique Application Number and in sequential format.
Sample Application Number - APP-Date-0001 the 001 will keep on increasing for entire day and counter should be reset next day. So for next day it should again start from 001 with current date.
The problem will occur when 2 users are creating application at the same time.
Keep counter and last date it was used in custom setting or similar object.
But access that custom setting with normal SOQL, not via the special custom setting methods like getInstance().
Finally - in that SOQL query use FOR UPDATE. https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_for_update.htm
If 2 operations start on same time - 1 will be held until other one finishes or timeout happens

What are the right data-structures to model this relationship, taking advantage of TTL in Redis

We are newbie's to redis and are trying to model the below relationship where there is a userid which could have multiple jid's and each jid will have it's own expiry time and need's to be expired at that time automatically and removed and we need to ensure that there could only be 5 jid's associated with a userid at any given point of time
userid1 : { jid1 : 1551140357883,
jid2 : 1551140357882,
jid3 : 1551140357782,
jid4 : 1551140357782,
jid5 : 1551140357682 }
From the last requirement figured that that the sortedset zset might be a good fit with name of set being the userid and field being jid and score of field being expiration time lie below
zadd userid1 1551140357883 jid1
this help us to enforce the 5 jid's per userid by checking the zset but then we are stuck on how to delete the jid's on expiry as we can't set the TTL for each element of the set. Any help in pointing us in the right direction to use the right data-structure for this use case would be great
Note : we may not want to introduce a batch job at this time to delete the expired tokens, and all our queries to redis will be by userid

Trigger countdown timer in email from the time it is sent, automatically

I am looking for a way where I can integrate a countdown timer in the email. This timer should last for one week from the time email is sent. The trick here is that the timer should start automatically once the email is sent and should expire exactly in a week after receiving in the inbox, so this can be integrated in automated email campaigns. Pre-defined timers with specified start/end date is of no use.
We had a similar task. After the user has registered on our website, we created him a coupon for the product, which was valid for 1 day and we sent a letter to him with this coupon. We wanted to add a countdown timer to this letter.
we tried many services, but we couldn`t find what we needed until we came across this site https://promofeatures.com/create-countdown-timer-for-email
They made the "Dynamic start date" control in the "Transaction" tab and that was what we needed. The essence of this button is that in the counter URL you need to specify the parameter "start_date" (counter start date), we need to specify this date, for example, manually write in the email letter (if the distribution service does not allow specifying such a date format)
or using a code (just such a letter we sent through our server), asking our developers to collect this date programmatically in a email letter, which was not a big deal.
The date format itself is clear:
d-m-y, where d - the day of sending, m - month, y – year
Th: m: s, where T - indicates that it is time, h - hours, m - minutes, s – seconds
Z + h: m, where Z - indicates the time zone, time can be either "+" or "-", h - hours of the zone, m - minutes of the zone, this value is +00: 00 UTC by default
Our developers used PHP code in the letter:
<img src="https://m.promofeatures.com/yv?start_date=
<?= date('d-m-Y\Th:m:s')?>Z-08:00" alt="https://promofeatures.com
" />
and in some emails we wrote it manually and at the moment the code would look like this:
<img src="https://m.promofeatures.com/yv?start_date=05-11-2019T09:11:54Z-08:00
" alt="https://promofeatures.com
" />
I hope this helps you if your question is still actual

Possibilities of AngularFire, sum of values entered by users, obtaining sum at main site with angular?

Suppose we want to develop a website. Key features:
home page (access for all) the main element on the page is the
sum of payments
registration and login page - mail address and password, account activation
the payment will be declared by the registered and logged in users through the form and a checkbox, when the checkbox is selected data should be uploaded to the server and saved if "pass verification" for example, do not exceed $ 10, each user in one day can only declare one payment
after possitive verification the sum from "number 1 above" is updated
additional features - user notification: when the last payment hasn't been made for more than six months, or if the total sum exceeds a certain level eg $ 1,000...
Is it possible that the whole solution would be based on angularfire? In particular:
the sum of payments - on main site the information about
the sum avaible for all visitors, so each time somebody visits the website
we will have to send request to Firebase to get all the records and
add the payments to finally show the sum on web site? With Angular we can do that?
Firebase enables queries/limits: e.g. last 20, but to get the whole amount you need to have knowledge of the previous value - in this case, increase in payments and visits will result in sending large amounts of data client side vs firebase - whether and how it can be optimized?
suppose that the activation of user account will require small payment
(paypal/transfer) is it possible to set account active when the
payment is done?

Bounce email handling mailbox full using salesforce triggers

I'm trying to solve the bouncing email issue based on "Mail box full" by creating a trigger that resends the message if the message contains "mail box full".
The issue I'm facing is that I need to limit the number of resend to 3 times.
What I have now keeps resending the email as soon as a bounced email is received.
My trigger is
trigger trgBouncedEmails on EmailMessage (after insert) {
for(EmailMessage myEmail: trigger.New) {
//mail box full bounced email
if (myEmail.HtmlBody.contains('full'))
{
Case[] parentCase = [Select c.Id from Case c where c.Id =: myEmail.ParentId];
if (myEmail.Subject.contains('Financial Review'))
parentCase[0].Resend_Email_Send__c = true; // this will trigger a workflow to send the email again.
Update parentCase;
}
}
}
How can I limit the resending, is there a way I can set a wait time before I do the "Update parentCase"
Is there a better way to solve this issue, knowing that I have different types of emails, each one has a different template and a different purpose.
EDIT
The system should automatically re-send the email 3 times in the frequency of 24hours, and then stops resending after 24hrs. My trigger keeps resending indefinitely and I'm trying to find a way to put a wait so it can only send 3 times in 24hrs period, like once every 8hrs.
#grigriforce beat me to the punch - I would also suggest using a field to count the number of retries, rather than a simple boolean value. Here's a "bulkified" trigger with essentially the same logic as the one you posted:
trigger trgBouncedEmails on EmailMessage (after insert) {
List<Id> parentCaseIds = new List<Id>();
for ( EmailMessage myEmail : trigger.New ) {
// mail box full bounced email for Financial Review emails
if ( myEmail.HtmlBody.contains('full') && myEmail.Subject.contains('Financial Review') )
parentCaseIds.add(myEmail.ParentId);
}
Case[] parentCases = [select c.Id from Case c where c.Id in :parentCaseIds];
for ( Case c : parentCases ) {
c.Resend_Email_Count__c += 1; // this will trigger workflow to send the email again
c.Resend_Email_Time__c = System.now(); // keep track of when it was last retried
}
update parentCases;
}
Update to space emails out evenly over a 24-hour period:
Rework your workflow to make sure it has been 8 hours since Resend_Email_Time__c was last set, and then schedule an Apex job to run every hour to pick up eligible Cases that need to have their emails resent, and call update on them to make sure the workflow doesn't go too long without firing:
global class ResendCaseEmails implements Schedulable {
global void execute(SchedulableContext sc) {
Contact[] cs = [select id, Resend_Email_Count__c, Resend_Email_Time__c from Contact where Resend_Email_Count__c < 4];
List<Contact> ups = new List<Contact>();
for ( Contact c : cs ) {
if ( c.Resend_Email_Time__c != null && c.Resend_Email_Time__c.addHours(8) < System.now() )
ups.add(c);
}
update ups;
}
}
**note that it's not a best practice to have this code in the class that implements Schedulable - this code would ideally be in another class that is called by the ResendCaseEmails class.
You can schedule this job to run once an hour by calling this code from the developer console:
ResendCaseEmails sched = new ResendCaseEmails();
String cron = '0 0 * * * ?';
System.schedule('Resend Case Email Job', cron, sched);
You could simply change the resend boolean on the case to an integer count of the send attempts and have your workflow rule re-send only while that count is less than 3.
Case[] parentCase = [Select c.Id, c.Resend_Email_Count__c from Case c where c.Id =: myEmail.ParentId];
if (myEmail.Subject.contains('Financial Review'))
parentCase[0].Resend_Email_Count__c += 1; // this will trigger a workflow to send the email again.
Update parentCase;
Also, I assume that you simplified the trigger to show the problem but if not you really need to bulkify it.
So, here's what you'd like to happen (feel free to correct me if I am wrong). You send an email, and if it bounces you'd like to re-send an email every 8 hours. The number of resends should be 3 max.
I would not use only triggers for this scenario. I'd instead design a solution using a Trigger, Scheduler, and maybe a custom table to keep track of the bounced email(s).
Let's call this table/object "Bounce Email Tracker". It'll have the following 3 fields:
Email Name (some unique description of email)
Email status (Sent, Bounced, ReSent, Failed)
Resend Count
Sent email Timestamp
If and when an email is sent you'd create an entry in this table using a trigger with the status set to "Sent" and the "Sent email . If the email bounces, another trigger would "update" the entry in the table to change the status of the record to "Bounced".
A scheduler will run regularly which will retrieve all records from this new table where status equals "Bounced", and check the last time the email was sent using the value in the "Sent Email Timestamp". It will do the following actions depending on the time sent, and resend count.
If the resend count is less than 3, and if the last email was sent more than or equal to 8 hours ago, send another email from the scheduler. Change the status of the record to "Sent".
If the resend count is more than 3, and the status is "Bounced", change the status to "Failed".
If the resend count it less than 3 but the last email was sent less than 8 hours ago, don't do anything.
I know this is a lot of effort, and I am sure it probably needs more thought, but this will provide a robust framework to track and resend bounced emails.
Hope this helps!
Anup

Resources