Intercept all Joomla outgoing emails & reroute them to a specified address - email

I'm working on a new Joomla site and am working on testing outgoing email. I'd like to be able to intercept all outgoing emails and reroute them to an address I specify. It is very useful in development when you have a copy of a live site with thousands of users, so email does not go to real users from the copy site.
It would be great to do this with a extension but have been unable to find one to do some. I'm also open to getting this done on the server side if necessary.
I found a Drupal module that does exactly what I'd like to do except it's obviously for Drupal and note Joomla.
https://drupal.org/project/reroute_email

On Joomla-Level you could create a system plugin that loads up own, monkey-patched JMail class.
I'm not sure if you would be able to extend the original JMail because of namespace conflict, so maybe you'd have copy it over and alter the addRecipient method:
public function addRecipient($recipient, $name = '')
{
$this->add('custom#email.com', 'custom name', 'AddAddress');
return $this;
}
References:
Related Stack Overflow answer: How to override core classes
Gist: plgSystemOverrides

Related

Custom tags in Jira email handler

Is there a way to make a Jire email handler ignore the From field in an email and go for a custom tag instead? I know I could work with the API instead but that's in the pipe. this is a temporary solution that will be used until a more robust system is built.
To clarify what we have today:
Email is sent to inbox, (hr#company.com)
Jira picks is up and creates an issue.
Jira looks at the From field and creates a uses if none exist.
What we're trying to achieve:
Form is filled out, and an area is chosen (hr, facilities etc.).
Form is posted to an API that creates an email (basically a no-reply adress over SMTP) and sends it to the appropriate inbox (for example hr#company.com).
Email lands in the inbox and Jira looks in it and creates an issue in project or label 'HR'.
Jira now looks in the email and finds custom tags named [user] and [user-email] (or something) and creates a user from the tag.
Example email
From: no-reply#company.com
To: hr#company.com
Subject: Some problem
Body: Explanation of problem
Have a good day!
/Mike
[user:"Michael Smith"]
[userEmail:"michael.smith#company.com"]
If we were to implement this system now, we would loose the possibility to create new users because all emails would come from the same "no-reply" adress.
I have searched in the Atlassian forums and such, but with no luck. Have not found anything in the official documentation, but I fear that I might be looking in the wrong place.
I hope that I'm being clear, and that someone has any idea if it is possible.
Thank you!
You need to write your own plugin and create your own Mailhandler.
For example you can use a regex which looks for the tag
[userEmail:"michael.smith#company.com"] and retrieve the emailadress from the string. Do the same for the [user]-tag, if the user doesn't exist.
Here is a tutorial that shows how to create and setup custom Message Handlers:
https://developer.atlassian.com/jiradev/jira-platform/guides/email/tutorial-custom-message-mail-handler-for-jira#Tutorial-Custommessage(mail)handlerforJIRA-Step7:Implementarealmessagehandlerback-end
The rest should be easy from here.

Detect image rendering in email

I know that services like SendGrid already have built-in plugins for this. But I want to build my own, custom, module for this.
Reason why I am doing this is my application uses several different smtp servers specified by user.
Is it even feasible to create one module for different smtp servers?
Absolutely! It's relatively simple too, at the most basic level you do the following:
Assign every email you send a unique id, in the email place a reference to a script on your server with the unique id. (e.g. <img src="https://example.com/img?id=1 >)
When /img?id=N is called have your code log the id and then serve the image.
A more concrete example in PHP would look something like:
Mail Sender:
$img = '<img src="https://example.com/img.php?id=' . generate_email_id() . '">';
mail("test#example.com", "This is a test.", "Hello! I hope this test works!" . $img);
img.php:
log_email_by_id($_GET['id']);
header("Content-type: image/jpeg");
readfile("pixel.jpg");

Send email from Redmine Plugin

I am writing a Redmine plugin. I already have the model, view and controller in place.
Whenever someone creates, updates or deletes my model I want to send an email to people in a certain group. (Similar to emails sent out by Redmine when someone creates or updates an Issue) Could someone please let me know what would be the best way to go about it?
Thanks!
I know it's been 2 years since you asked but I had the same issue and I figured out how to send an email with my plugin.
What you have to do for a plugin named my_plugin is :
1. Create a Model which inherits from Mailer.
So if I want a mailer named MyPluginMailer :
I create redmine_folder/plugins/my_plugin/app/models/my_plugin_mailer.rb
I create the MyPluginMailer class which inherits from the redmine Mailer
Like that:
class MyPluginMailer < Mailer
end
2. Create a method to call on the mailer.
Say I am writing a news plugin for redmine.
I want to send an email which summarizes the article I submitted so that users do not have to poll the plugin each time they want to know if there is something new.
I create a method in my mailer class :
class MyPluginMailer < Mailer
def on_new_article(user_to_warn, article)
mail to: user_to_warn.email, subject: "New article: #{article.title}"
#article = article #So that #article will be available in the views.
end
end
You can call this method in your Article class in an after_create callback for example.
3. Create some views for the method.
I have to create 2 differents files :
my_method.html.erb
my_method.text.erb
or else redmine is going to crash with a "template not found" exception.
So in my redmine_folder/plugins/my_plugin/app/views/my_plugin_mailer/ I create
on_new_article.html.erb
on_new_article.text.erb
In my on_new_article.html.erb I write something like :
<h1><%= #article.title %></h1>
<p><%= #article.summary %></p>

Drupal email users

I'm using Drupal 6.16: When a user creates an account on my site I have them select a category (ie children, youth, adult, etc). This is done with the select list box using the content_profile module. I have a content type that posts an announcement. In this content type is a check box that says 'email group'. Right now it does nothing, but what I would like for it to do is e-mail all the users that are associated with the group they chose when signing up for their account. If this will require extra code please be specific as I am not a strong php programmer.
Thanks for the help!!
msindle
There might be some module that do it exactly, but I don't think so.
I would have done it using few building blocks:
Retrieve the list of emails using Views - define a view that gives you the addresses according to a given group argument.
Use Rules module that will send an email notification after node is created.
Combine the two (this is the hard part) - insert the values from the view as the recipients for the email. You might be able to do it using PHP inside the Rule definition, plus view execution.
Try to accomplish it, and if you get into troubles, you are welcome to contact me via shushu.i#gmail.com
I would try http://drupal.org/project/subscriptions module + http://drupal.org/project/messaging module. You can set preferences for automatic subscribing to content type. Maybe Rules module can subscribe users automatically after creating or updating content_profile. Or maybe Rules can flag users after creating or updating content_profile and Subscription module could autosubscribe flagged users.

How to send form contents anonymously via email

How do you send the content of a website form to an email address without disclosing the email address to the user.
Thanks!
PS: If at all possible, I would like this to be in HTML JavaScript Ok, anything I guess.
Not possible. You can however put a "fake" from header in the mail. You'll only risk it to end up in the junk folder.
HTML doesn't provide any functionality to send mails. You'll really need to do this in the server side. How exactly to do this depends on the server side programming language in question. In PHP for example, you have the mail() function. In Java you have the JavaMail API. And so on.
Regardless of the language used, you'll need a SMTP server as well. It's the one responsible for actually sending the mail. You can use the one from your ISP or a public email provider (Gmail, Yahoo, etc), but you'll be forced to use your account name in the from header. You can also register a domain with a mailbox and just register something like noreply#example.com and use this to send mails from.
Update: JavaScript can't send mails as well. Like HTML it's a client side language. You'll need to do it with a server side language. All JavaScript can do is to dump the entire page content back to the server side. jQuery may be useful in this:
$.post('/your-server-side-script-url', { body: $('body').html(); });
with (PHP targeted example)
$to = 'to#example.com';
$subject = 'Page contents';
$body = $_POST['body']
$headers = prepare_mail_headers();
mail($to, $subject, $body, $headers);
Update 2: if you actually want to hide the to header in the mail, then you'll need to use the bcc (Blind Carbon Copy) instead. This way the recipient addres(ses) will be undisclosed. Only the from, to, cc stays visible.
If you mean doing so on a client side, using mailto: link - you can not.
If you mean any way, yes - you submit the form contents back to your server, and have your back end script send the email.
You can do the form in HTML, but the posting will need to be done in a script. Even if you don't expose the email address, the script can be used to spam that email address. This is why you see captcha being used in such cases.
There are scripts available for most languages. Check to make sure their are no known security problems for the scripts. The original Matt's script in perl had problems, and the Perl community created a more secure version.