I have below code to send an email from browser client.
Send Mail
However, I am looking for an email app (Outlook) which should pop up with recipient, text and attachment. After that, all that is left to do for me is pressing "send" in my outlook.
I've been trying for a while, but I couldn't find a solution. Any help would be appreciated.
While Recipients, Subject and Body are supported in the RFC mailto url syntax and implemented by some clients (please note the correct encoding and escaping of special characters like spaces), Attachments are not supported at all.
That would be difficult also, how would you know which (local) file path to pick? Also, the client would open up a potential security risk.
Related
I was asked if changing an email's subject is possible when someone receives it in Outlook. Is it?
I was thinking it may be. The same way user agents are used for browsers maybe? I'm pretty new to emails but searching on the internet didn't help and I've already spent a few hours doing that.
You don't have to solve it for me, just point me to the right direction would suffice. Either way it's something I would like to learn doing.
TL;DR Email subject text change based on recipient (Outlook specifically).
Email clients do not support dynamic code, so you can't do this with client-side JavaScript.
SMTP servers sending email have no way of knowing which client will be used to open the email. (They don't send email in response to the email client asking for it).
What you want is impossible.
So, I have a site where I'd like users to send a document (preferably) a pdf file or word doc on button click to a specific email address.
I read that mailto is not a good way to do it because of all the potential spam thats possible from spambots. Disassembling and reassembling the email address doesn't seem that hard to crack either. I don't understand how encoding works so I'd be grateful if someone explains that.
What I would like is: when the user clicks the send button, it opens up an email client with the address of the recipient and of course the mail client would have the ability to send attachments. Whats a good way spam protected way to do this?
The mailto protocol does not include attachments. And it would be a huge security issue as well. Some Outlook-related examples can be found on the internet, but in the case it has been working in the past, it is not possible nowadays and at least not platform independent in every case.
You can't send files with mailto. What you should do instead, which would also protect you from spam bots, is upload the file to your server and send the mail with the attached file from there.
Indeed it is an awesome day to everyone but not for me because I've been handling this battle cry for more than 13 days now and cant get it done. I have searched across the web but cant find the solution that can get my butt out of this mess. And yes stackoverflow is always my last resort when things get worse.
Can anyone suggest what is the best way(or even alternative) in sending email using js or jquery ?. Perhaps a simple snippet would do. Thanks!
You cannot send an email within the client browser. If your website is running on your own webserver, you can send a request from within the browser to your server that sends an email. If you're running a node.js server, there are many email apis.
For example, my business is a Mailjet customer, and so I can use the node-mailjet api on my server-side. Also there's https://nodemailer.com/ and similar npm packages.
Sending email only using javascript on client-side is not possible. By that you would give full control to user what and where he sends email - cool spam solution..
I wouldn't recommend to expose service from server that send email to client-side from server-side with full settings of message that will be sent. You don't want to allow spamming.
Only good approach is to predefine email on server and then when triggering action occurs resolve dynamic values in email on server and send email from server. Still you have to ensure user cant spam with some security policy.
So how to get out of this ? Implement service on server that will send emails for you (called with AJAX), lets say by code name and parameters. On server-side, choose template by code-name and resolve it by parameters passed with server request. Implement you security policy so you can be sure user cant spam (for example when user can choose to which email address will be message sent). Then pass it all to SMTP.
I am aware that there have been multiple questions with respect to this issue. However, I have not yet found a satistactory answer.
I have built a medical app using a whole lot of JavaScript. It runs on both android and iOS. This app determines which protocol to use under certain conditions for a particular patient.
The doctor can send these considerations and an indication of the protocol to use to himself and to some other institution that needs to use it. I use mailto for that.
Since there are however a lot of protocols, just a protocol name can lead to errors. So, we would like to send the relevant protocol in pdf file-format as an attachment with the email.
So far, I have not yet been able to do that. However, I see that that there are a lot of apps that allow you to send documents (or pictures) as email attachments, using the available email client on the mobile device (and also through whatsapp and other comms methods).
Does anybody have any ideas please?
Apart from this, another thing mailto does not allow is formatted text. It would be very nice if I would have a possibility for that too.
You can use MFMailComposeViewController for iOS. Check out this link.
In Android you could use the Java Mail API. A good tutorial is posted here.
You can add an attachement like this:
public void setAttachment(String file, String name) throws MessagingException {
content.removeBodyPart(attachment);
DataSource source = new FileDataSource(file);
attachment.setDataHandler(new DataHandler(source));
attachment.setFileName(name);
content.addBodyPart(attachment);
}
where content is a membervariable of type MimeMultipart and attachement of MimeBodypart
Can i send a pdf file through javascript ?
i have a link ,when i click the link it need to open OUTLOOK with title and the pdf file as attachment.also some body text.
Is it possible ?
Thank you .
Security restrictions will not allow this. Imagine the potential issues.
Also, you have absolutely no control over which email client is opened. This is set by the user for whatever operating system they are using.
Since it is not possible I suggest gathering all the information you need from your page (subject, body, which file, etc.) and submitting that to your server for processing. On the server you can send your e-mail using smtp.
Since adding the PDF as an attachment is not possible, I would recommend putting the link to it in the email body. This will save on the user's bandwidth and can be done with a simple mailto: link.
Send PDF
This will also work on any system with whatever email client the user has as their default (i.e. you're not limited to Outlook).