How to sent an email background with Swift code (macOS) - swift

this code works fine but it pops a window, then have to click send. Can I send it in the background without pops a window?
Thank everybody!
import Cocoa
class SendEmail: NSObject {
static func send() {
let service = NSSharingService(named: NSSharingServiceNameComposeEmail)!
service.recipients = ["abc#dom.com"]
service.subject = "Vea software"
service.performWithItems(["This is an email for auto testing through code."])
}
}
SendEmail.send()

You can't do that, this would be quite not secure if a dev could sent any email from user's address without even letting him know
In background you can send a http request to your server which will send an email, but it will send it from your developer/organization/etc address, not from user's one ofc.

Related

I am using NSSharingService in my macOS Swift app. Is there any way to make sure the default mail client is configured with a valid account?

I am using NSSharingService to prepare an email with attachment for the user of my macOS app. My code is:
let emailService = NSSharingService.init(named: NSSharingService.Name.composeEmail)
if emailService.canPerform(withItems: [emailBody, zipFileURL]) {
// email can be sent
DispatchQueue.main.async {
emailService.perform(withItems: [emailBody, zipFileURL])
}
} else {
// email cannot be sent
// Show alert with email address and instructions
self.showErrorAlert(with: 2803)
}
This works correctly, but if the code is executed on a fresh system, Apple Mail will be opened asking the user to configure an email account. Some users may not understand what is going on in this situation. Is there a way to ascertain if the default Email Client is configured, so that I can inform the user if it is not ? Thanks for your help.

Tracking email read when sender opens the email

I have implemented email tracking feature.
When the receiver opens the email, the read count is increased.
But when the sender opens the email, it also increases the read counter.
Is there any way in which the read counter does not increase when the sender reads the email?
Thanks in advance!
In my background.js, I used chrome.webRequest API to block the webrequest which renders the pixel image for the sender.
This way when the extension is installed for the sender, then the pixel image request will be blocked when the sender will read own email.
Here is the reference code from chrome.webrequest API-
//block all the requests to www.evil.com
chrome.webRequest.onBeforeRequest.addListener(
function(details) { return {cancel: true}; },
{urls: ["*://www.evil.com/*"]},
["blocking"]
);

Upon button press, open up mail and have user send email to specified address?

I was wondering if there is a relatively straightforward function that would allow a user in my app to press a button, have the mail app open, and let that user write a brief message to the already established (& greyed out) receiver of the email?
let email = "foo#bar.com"
let url = NSURL(string: "mailto:\(email)")!
UIApplication.sharedApplication().openURL(url)

Ionic External link from email to application (Deep Linking)

I'm trying to add a link from email
that click on it will open the application in the relevant page.
I haven't found a solution for that yet.
If you do have any recommendation how to do that, i'll be glad to know.
Thanks.
This is the scenario :
user click forgot passowrd.
email is sent via server.
the email contains link for reset the password (this is what i need)
user click on the link an enter the reset password page on mobile application.
It's relevant to say that it should support All ionic platform (most important ios/ android)
I agree with #LiadLivnat in the past I used Custom-URL-scheme.
Here is a snippets of code:
Consider you have some run with reportAppLaunched method:
app.run(function($rootScope){
/* ... */
$rootScope.reportAppLaunched = function(url) {
$log.debug("App Launched Via Custom URL: " + url);
$rootScope.$apply(function() {
if (url.substring(0, 'mailto:'.length) === 'mailto:') {
$rootScope.navigateTo('forgot_password_view', {action: url});
}
});
};
}
Now this global function will be fired when, in my case, user opens contact list and clicks on some member. Android will ask with witch application you want to open this contact and you select . The method handleOpenURL is triggered and you can redirect to specific view in your application.
function handleOpenURL(url) {
var body = document.getElementsByTagName("body")[0];
var rootController = angular.element(body).scope();
rootController.reportAppLaunched(url);
}
Hope it will help,

Launching the mail app from a WIndows Store app

I'm trying to create a windows store app that will launch the default mail app (WinJS 8.1). I haven't touched this for a while, but it was working correctly before 8 - 8.1 upgrade. The code looks like this:
var interval = setInterval(function () {
clearInterval(interval);
var formattedBodyText = bodyText.replace(/\n/g, '%0d');
var mailTask = Email.SendNewMail.sendEmail(emailAddress, subject, formattedBodyText);
}, 500);
And the sendEmail function:
sendEmail: function sendEmail(addess, subject, body) {
var mailto = new Windows.Foundation.Uri("mailto:?to=" + addess + "&subject=" + subject + "&body=" + body);
return Windows.System.Launcher.launchUriAsync(mailto);
}
Oddly, this seems to launch Chrome (I assume because that's my default browser). How can I get it to launch the mail app? Has this changed since the 8.1 upgrade?
EDIT:
It looks like the default program for opening mails was changed to Chrome. So, I suppose my question is now: is it possible to FORCE the mail app to open, rather than whatever is associated with the mailto: url? I noticed there was an ms-mail uri - would that be safer to use?
You can't determine which is default mail app in Windows Store app. Moreover there's no way to open Mail app forcefully in Windows Store app. It doesn't make sense. Some user (Like me!) might not like default mail app. So I would recommend to stick to share charm for sending emails.