Old sendmail with Perl need to embed attachment - perl

Before someone says I need to use MIME::Lite or another pm... My job has a BASE set of pms and I can't change them... I really need help working within the confines of my system:
We have been using this code to send email to our clients for years:
open MAIL, "| /usr/lib/sendmail -t";
print MAIL qq[To: $email
From: MyFooFoo\#www.foobar.com
Reply-to: do not reply
Subject: This is the subject
Hello, this is the body of the message
Thank you
];
close MAIL;
Now, they are asking me to EMBED an image in the email... I have tried to use Unix sendmail - html embed image not working as a reference, but I can't figure out the boundary/mime types...

You have to build your mail as a MIME message with multipart/related and then feed it to sendmail. See https://www.rfc-editor.org/rfc/rfc2110, it contains examples of how such mail looks like and how to embed images into HTML mail etc. You probably need a way to base64 encode data, but either you can use MIME::Base64 for it, an external command line tool or program it yourself in just a few lines (see source of MIME::Base64).

Related

Intercept all emails sent from Xampp Mercury Mail Server

I have a Xampp Server that I use only in a development environment. In order to preview emails that would be sent from the live sites without actually sending them I would like to intercept all the emails sent from this server. I would like to be able to either send them all to a specific email or save them as files instead of sending them to whatever address they're set to go to. This way I can make sure they are correct without accidently sending emails during testing.
I found a similar question with an answer
here
but was unable to find a way to open any of the dialogs in the answer and so it didn't get me very far.
Thanks in advance for your help!
You can accomplish this using the sendmail configuration within your php.ini.
Create a file named smtp_catcher.php and the set the sendmail_path
sendmail_path = "php C:\path\to\file\smtp_catcher.php"
Then in your smtp_catcher.php add this block:
#!/Applications/XAMPP/xamppfiles/bin
<?php
# create a filename for the emlx file
list($ms, $time) = explode(' ', microtime());
$filename = dirname(__FILE__).'/'.date('Y-m-d h.i.s,', $time).substr($ms,2,3).'.emlx';
# write the email contents to the file
$email_contents = fopen('php://stdin', 'r');
$fstat = fstat($email_contents);
file_put_contents($filename, $fstat['size']."\n");
file_put_contents($filename, $email_contents, FILE_APPEND);
# open up the emlx file (using Apple Mail)
exec('open '.escapeshellarg($filename));
?>
Now I am not sure what extension you'll need to use to view the emails but this should catch all emails going out.
NOTE: make sure that php is in your window's environment PATH

Automatically forward email attachment as textual link in another email

This might be an odd request but I know there must be a way. Here's what I have and would like to do:
Input:
1) An email is sent with an attachment
2) The attached file is a jpg image
Output:
3) An email should be received with a tiny link in the email body
4) The tiny link should point to the image viewable in a browser
Additional Criteria:
5) The destination email address to which the original message is sent can be altered
6) The format of the original mail cannot be altered; the image is always attached
7) The process must be automated, triggered by the original email
I have gmail accounts and a Linux server that could potentially be used but not sure where to start. I've searched quite a bit and found a lot of software that do similar tasks but nothing like this specifically. It seems to be a fairly complicated task and I could use some ideas. Any help is appreciated.
This was a bit of a challenge but I managed to get it done. Here's how:
Input:
1) Send the email with attachment to local postfix smtp server
Processing:
2) Have postfix call procmail when email is received
3) Use procmail as a filter to conditionally call a script
Custom script:
4) Use munpack to convert the attachment to file
5) Use a script to upload the image file to imgur
6) Use a script to make the imgur link tiny
Output:
7) Send an email using mutt with the link in the body
The main problem I had was setting up postfix and finding bugs in the clients trying to send email to the local postfix server. I used an array of tutorials, IRC and tools to debug but tcpdump revealed the final smoking gun.

How to set up an email server that will accept a URL in the subject of an email and respond with a copy of that webpage

I'm trying to piece out how difficult it would be to set up an email server that will accept a URL as the subject of an email and respond with an attached copy of said webpage, or element(s) of that webpage (ie, an image from the page, or all of the videos on the page).
I don't necessarily need the code written for me, but would appreciate if someone could suggest a starting point.
I have very little web-programming knowledge (some C++, some Actionscript), which is partly why I don't even know where to begin.
There is several ways to achieve this.
In most unix MTAs you can set up an alias to pipe all messages for some address through a program.
This program need to parse the message header for the "from" and "subject", fetch the url and sent it back.
You can also do this with a program like fetchmail, so you dont even need to make something in the server side.
Finally, several languages have wonderful libraries fetch the mail using POP3, parse it, fetch the URL from the subject and compose a new mail message. Should be no more than 100 code lines with perl or python.

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.

Why can't I send mail with Perl's Net::SMTP?

I use Net::SMTP to automate emails. I want to get notification if someone use email into Outlook I used this:
$smtp->datasend("Disposition-Notification-To: to.me\#domain.com");
The email sent succesfully but the Outlook client is not getting the notification.
Here is a snippet of the code:
$smtp = Net::SMTP->new("my mail host");
$smtp->mail("my\#adress.com);
$smtp->to("someuser#domain.com");
$smtp->data();
$smtp->datasend("Disposition-Notification-To:my\#adress.com");
$smtp->datasend("blah balh");
$smtp->datasend();
$smtp->quit;
The Net::SMTP module is pretty low level for this sort of stuff. You'd have an easier time with a higher level module such as Email::Sender.
It's possible the Outlook client agent is not set up properly to listen for these events. Can you send mail to it via another method? You need to isolate whether it is the listener or the sender that is having problems.
If you can receive mail in Outlook, but just not from your code, then it's your code at fault. Please include more contextual code in your question -- e.g. how is the $smtp object being constructed? Are you making a $smtp->dataend(); call as per the documentation?
Edit (after you included some code): there is a typo in that code; are you using use strict; use warnings; at the top of your script or module? Can you receive mail to your client from other means?
Edit2: if notification is all you're lacking, you should probably dive into the Outlook documentation to see what the criteria are for receiving such notification. e.g. you might need to provide a valid "Date:" header.
You need to include a blank line between the last header and the actual body of the message.
You also seem to be missing a space after the header prefix.
I'd guess that one of these is stopping Outlook from interpreting the header correctly.
Try this:
$smtp->data();
$smtp->datasend("From: my\#address.com");
$smtp->datasend("To: my\#address.com");
$smtp->datasend("Subject: test mail");
$smtp->datasend("Disposition-Notification-To: my\#adress.com");
$stmp->datasend("\n");
$smtp->datasend("blah blah");
$smtp->dataend();
$smtp->quit;
Perhaps Outlook is requiring the Return-Receipt-To header (non-standard, but you are sending to Outlook, afterall).