Open default mail app from within Qt with some html - html

How can I open the default compose mail window from the user's mail app from within a Qt app?
I found there is some class for mobile with Qtmobility, but I don't have access to this class as I'm working on a desktop app.
I also found people to use a URL sheme with a mailto in it. This isn't working for me because the html is stripped at some point, probably because of the url being too long and the html is not rendered in html but in plain text.
How can I precompose a mail in Qt and open the default mail app?

There is no built in way in Qt to send email with HTML formatting. The Mailto method will work for unformatted text, e.g.
QDesktopServices::openUrl(QUrl("mailto:?to=recipient#example.com&subject=The subject of an email&body=Here is some email body text", QUrl::TolerantMode));
But this cannot be used for html formatted text.
If you absolutely need HTML you will need to look at the options for your platform(s):
MAPI for Windows
AppleScript and Mail.app on OSX
Mail on Linux

Old topic but :
You could also try another way, as I did, using a web service.
I have a php web service that send email to a specific mail address, so I just send the message data to this web service, that will handle the rest for me.
This is to abstract yourself of using a desktop software that most of the time users don't have ( we all use gmail anyway, so you know ... ).
In php :
// sending mail to my#address.com
$headers ='From: sender#address.com'."\n";
$headers .="Reply-To: replyto#address.com"."\n";
$headers .='Content-Type: text/plain; charset="iso-8859-1"'."\n";
$headers .='Content-Transfer-Encoding: 8bit';
mail('my#address.com', '[TAG] mail subject', "some body text.", $headers);
Careful of security though !

Related

Send HTML based e-mails using wordpress

I'm looking for a code that sends a pre-written, formatted email when a link is clicked (Wordpress)
I tried this:
YourName#YourSite.com
But there are two problems with it
It only works if the person clicking the like has an offline email client configured like Outlook or Thunderbird.
It doesn't format the email correctly, and doesn't include any links
I was wondering if I can use Contact form 7 with placeholder? Also, will it send the email from single IP address?
It only works if the clicker have any offline email client configured like Outlook or Thunderbird
Thats how mailto: works. It will open in the default mail client installed in your computer.
It doesn't format the email correctly an doesn't include links
Try the below code.
var emailBody = "1st line.\n 2nd line \n 3rd line <a href='http://yahoo.com'>Yahoo</a>";
emailBody = encodeURIComponent(emailBody);
href = "mailto:me#somesite.com?body=" + emailBody;
Set this href variable to the href attribute of your a tag
document.getElementById("mailme").href = href;
You can configure the email templates that contact form 7 sends out in the 'Contact' section of your wp-admin panel. Yes, they will all come from one IP address, that of your server, but unless you're expecting thousands of mails every hour to be sent from it, that's hardly going to be a limitation.

Does the Win 10 UWP EmailMessage API support having an HTML body?

I have tried the following code to send an email from an Universal Windows Platform app. It works fine when I use EmailMessageBodyKind::PlainText. However, as indicated in the code below, EmailMessageBodyKind::Html seems to launch the email client with no content. Does anyone know what else needs to be set to get this to work - the documentation is sparse 8 (
using namespace Windows::Storage::Streams;
using namespace Windows::ApplicationModel::Email;
using namespace Windows::Security::Cryptography;
auto bin = CryptographicBuffer::ConvertStringToBinary(
L"<html><body>this <b>is</b> text</body></html>",
BinaryStringEncoding::Utf16LE);
auto memStream = ref new InMemoryRandomAccessStream();
concurrency::create_task(memStream->WriteAsync(bin)).then(
[memStream](unsigned)
{
auto email = ref new EmailMessage();
email->To->Append(ref new EmailRecipient(L"test#gmail.com"));
email->Subject = L"Email Report";
auto randomAccessStreamReference = RandomAccessStreamReference::CreateFromStream(memStream);
email->SetBodyStream(EmailMessageBodyKind::Html, randomAccessStreamReference);
EmailManager::ShowComposeNewEmailAsync(email);
}
);
Well, I got some bad news for you.
It is not possible to do so using EmailManager.ShowComposeNewEmailAsync
Regarding using SetBodyStream with EmailMessageBodyKind.Html, we have this from MSDN forum:
Currently, the EmailMessageBodyKind.Html won't work for create a new
HTML e-mail and there is no other way as a workaround, I've checked
the internal resource, this API is used for populating messages from
App server and save e-mail message into local folder.
The thing is: EmailManager.ShowComposeNewEmailAsync uses mailto to send the message and, as stated in some other question already answered here:
Section 2 of RFC 2368 says that the body field is supposed to be in
text/plain format, so you can't do HTML.
However even if you use plain text it's possible that some modern mail
clients would render the resulting link as a clickable link anyway,
though.
That being said, you're relying on the mail client to render that HTML for you.
I've tested this using Windows 10 Mail Client, Gmail and Outlook (both the later on a web browser), and all of them failed to render a simple HTML <b> tag on the mail body, showing it as plain text instead.
Now, for the alternatives (from that same MSDN forum thread):
Note that if I use the ShareDataContract (DataTransferManager), I am
able to set the HTML in the request and it will appear in the email
body if the user chooses to share via Mail. However I would like to
skip the Share UI and go directly with composing an email with
recipient already populated, HTML body, and image attachments.
One alternative is to persist the HTML body to a file and then include
that file as an additional attachment, however that is not ideal
The DataTransferManager successfully formatted the HTML message. Here's a small sample of how your sample code would look like, adapted from MSDN:
void YourView::ShareHtml()
{
DataTransferManager^ dataTransferManager = DataTransferManager::GetForCurrentView();
auto dataRequestedToken = dataTransferManager->DataRequested +=
ref new TypedEventHandler<DataTransferManager^, DataRequestedEventArgs^>(
this, &YourView::OnShareHtml);
DataTransferManager::ShowShareUI();
}
void YourView::OnShareHtml(DataTransferManager^ sender, DataRequestedEventArgs^ e)
{
DataRequest^ request = e->Request;
request->Data->Properties->Title = "Email Report";
String^ html = L"<html><body>this <b>is</b> text</body></html>";
String^ htmlFormat = HtmlFormatHelper::CreateHtmlFormat(html);
request->Data->SetHtmlFormat(htmlFormat);
}
The limitations of this approach are:
You cannot force the user to select e-mail as the sharing option
You cannot previously specify the mail recipient.

Sending current HTML page in an email with mailto

I have a page (specifically, a Chrome developer extension) used for debugging client installations of some software. If clients need more help for a specific problem that they are observing, we want them to be able to email us with documentation of the problem.
Is there a way for a mailto to add (as an attachment or a frame within the email body) a file of the current html page the mailto is on? The page is dynamically generated locally, so it would be preferable if the page didn't have to be uploaded anywhere but the email.
Look at this w3schools example: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_links_mailto_subject
(formatted excerpt, you will want the href="" to be all on one line)
<a href="
mailto:someone#example.com?cc=someoneelse#example.com
&bcc=andsomeoneelse#example.com&subject=Summer%20Party
&body=You%20are%20invited%20to%20a%20big%20summer%20party!" target="_top">
Send mail!
</a>
You can use javaScript to insert into the link the page as you need.
EDIT:
Just noticed that you might want to be careful with 'larger' pages, as there is a limit to how long a GET request (which this is) can be: maximum length of HTTP GET request?
tl:dr:
You might want to narrow the scope of what code is included if you use this method
Short answer: No.
The mailto in an a tag is only used to specify a link to an email, not the contents of said email. You would need to use some sort of server-side AJAX call. I would recommending using PHP's mail() function if you can.
Example
You would need to set the email header to be HTML compliant.
So, if you're using the PHP mail() function:
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail("target#something.com", "subject", "PLACE HTML HERE", $headers);
Then you could theoretically just pass off in the AJAX request all of the data from the page:
$.ajax({
url: "http://my.url.com/endpoint/",
method: "POST",
data: {
page: $("html").html()
}
});
Which you would then just embed somewhere in the email, or straight into the body. You could even add extra data for the GET and POST parameters present.
Note
While I can see this being used for some debugging, a lot of errors are caused via Javascript failing in some way or your PHP/server-side code failing. I'd recommend that whatever path you choose, including one I haven't covered, you should also include data from the console, POST, and GET variables if you have access to those (although be careful not to expose the POST and GET variables unnecessarily).
There are also a lot of tools like Chrome Remote Desktop that can help you view specific errors and problems that users are experiencing.
Alternately, to get around the mail() function, you could have embedded debugging Javascript which can dynamically send debugging information from their browser (via an AJAX request) to a server, that intercepts it for you to analyze and debug.
its not possible to include attachments using mailto:
one way to do this is to use mailto: to create a text message with two links:
the page url
the url of a png capture of the page.
there are chrome apis to capture the screen, and you can use your server or something like imgur to save the capture. probably better to use your own server that receives the images as imgur could be a privacy concern for your users.
It seems like a full answer is impossible, but I thought I'd share the route I took.
I have a button with id='save-log'. In the page where I add all the necessary events, I have
document.getElementById('save-log').addEventListener('click',
function(e){
chrome.runtime.sendMessage({
log: document.body.innerHTML
});
}
);
Then in a background page I have
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
chrome.tabs.create({
url: "save-log.html?" + message.log
});
}
);
And finally, in save-log.html I have the necessary styling information, with an empty body, and run the script:
document.write(decodeURIComponent(location.search.substring(1)));
Now there's a new tab with a full copy of the developer extension panel, and the user can save the html page and send it to whoever they want.

Sending html message via Skype4com

I want to send a message in skype with html tags using skype4com library. How I can do this? Is it impossible?
I tried to send a message to the body Hello , but in Skype it remains the same.
You can't because you can't communicate with Skype anymore via the API :
https://gigaom.com/2013/07/13/skype-says-it-will-kill-desktop-api-by-end-of-2013/
You should now be using URI
http://msdn.microsoft.com/en-us/library/office/dn745878(v=office.15).aspx#sectionSection0

Drupal webform html mail

I've made a contact form with Webform module. But it doesn't send HTML emails. I have installed HTML mail, Mail MIME modules. HTML mail module's send test works fine, but mail from Webform is always converted to plain form instead of HTML. I've tried to set email headers using this function:
function mytheme_webform_mail_headers($variables) {
$headers = array(
'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
'X-Mailer' => 'Drupal Webform (PHP/'. phpversion() .')'
);
return $headers;
}
But it still doesn't work.
Edit: I've found that setting header works, so the mail is send as HTML, but the problem is, that content of email is converted to plain format (all HTML tags removed and "formatted" respectively)
it's an old post, but maybe still useful:
http://drupal.org/project/mimemail
this modul adds a checkbox to select, weather you want to send html-mails or not
Looks like this should be a built in feature (as it was in Drupal 6 version of the webform module) but there are some issues with the Drupal 7 version. The webform module code points to issue https://drupal.org/node/1043086. Keep an eye on that thread for an update.
Probably, You should use mailsystem module together with htmlmail module, to define the email processing spesially for Webform module.
http://drupal.org/project/mailsystem
http://drupal.org/project/htmlmail