How can we add attachment to default mail Application Using NSWorkSpace in cocoa Mac OSX application - swift

I am using NSWorkspace to set TO, CC, BCC , SUBJECT and body text in default mail application through my application. How can i add attachments using NSWrokSpace?
Is there any way to attach files in the default mail app using NSWorkSpace?
I have tried using NSSharingService but problem with NSSharingService is that you cannot set CC and BCC email addresses in the default application Email Compose.
Is there any way to add CC, and BCC recipients using NSSharingSerivce ??
or is there any way to add attachments in mail using NSWorkSpace??
My code to open and set TO, CC and BCC is here
NSWorkspace.sharedWorkspace().openURL(NSURL.init(string:"mai‌​lto:(self.txtTo.‌​stringValue)"+"?subj‌​ect=YourSubject"+"&c‌​c="+self.txtCC.strin‌​gValue+"&bcc="+self.‌​txtBcc.stringValue)!‌​)
And Using NSSharingService i can set only recipients as TO
service!.recipients = [self.txtTo.stringValue]
service!.subject = "Subject"
thanks!.

It looks like NSSharingService has the method performWithItems, which takes an array of the things you want to share.
It appears you can create a sharing service of type NSSharingServiceNameComposeEmail and then attach a message body and a file to attach.
I've never used NSSharingService before, so the above is based on some Googling and reading the docs. (And I mostly work in iOS these days so my Mac OS is getting a little stale.)
Check out this link:
http://cutecoder.org/featured/programmatically-sending-rich-text-mail-attachment-mac/

Related

How I can send a email with attachments in Camunda?

I am new here and also using the Camunda application, my question is that when I try to send an email with Camunda's own extension ( camunda-bpm-mail ) I don't see that I have the option to send attachments along with the email and I would like to know if there is a way to do it. Thank you.
The camunda-bpm-mail component supports attachments. See:
https://github.com/camunda-community-hub/camunda-platform-7-mail/blob/6470b1351818d90b61d941fe05b1205e14a637a4/extension/core/src/main/java/org/camunda/bpm/extension/mail/send/SendMailRequest.java#L40
https://github.com/camunda-community-hub/camunda-platform-7-mail/blob/6470b1351818d90b61d941fe05b1205e14a637a4/extension/core/src/main/java/org/camunda/bpm/extension/mail/send/SendMailConnector.java#L121
and includes an example;
https://github.com/camunda-community-hub/camunda-platform-7-mail/tree/main/examples/print-service/src/main/resources

Send Email with attachment to a specific recipiant , using share Content WinRT

I'm using WinRT and I want to send an email with attachment to a specific recipient programatically, that means the user of the app will not write the recipient address.
I found to solutions that dont correspond to my needs.
the first one is to use mailto protocol like this :
var mailto = new Uri("mailto:?to=ratatata#gmail.com&subject=our first subject &body=as you know this is our first mail baby ");
await Windows.System.Launcher.LaunchUriAsync(mailto);
this solution allow me to specify the recipient but the mailto protocol dont support attachement.
the second one is by using Share Content , like this microsoft sample ,
https://code.msdn.microsoft.com/windowsapps/Sharing-Content-Source-App-d9bffd84
this solution allow me to attach any type of files , but the user of the app should write the email address of the recipient.
NB: any other methods using MessageEmail , and system.net.mail dont work !
Any help please !!

Sending email attachments via UWP EmailManager not working

Sending an attachment from a universal app with the following code is not working, why?
Dim emailMessage As New EmailMessage()
emailMessage.[To].Add(New EmailRecipient("a#b.com"))
emailMessage.Subject = "Test"
emailMessage.Body = "Hello World"
Dim localAppFolder = Windows.Storage.ApplicationData.Current.LocalFolder
Dim file = Await localAppFolder.CreateFileAsync("SomeFile.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting)
Await Windows.Storage.FileIO.WriteTextAsync(file, "aaaa")
Dim fileRef = RandomAccessStreamReference.CreateFromFile(file)
emailMessage.Attachments.Add(New EmailAttachment(file.Name, fileRef))
Await EmailManager.ShowComposeNewEmailAsync(emailMessage)
To, subject and body show fine in Outlook, but the attachment is missing: Outlook screenshot
I believe it is because the Outlook is a Desktop app. As I understood, the EmailManager.ShowComposeNewEmailAsync uses mailto: protocal to launch mail client app and use share to provide the email content.
If you choose the mail store app when the select default app dialog launches, you will be able to see the attachment as following:
If you have previously chosen Desktop Outlook app as the default as for mailto protocol, you have to change the default app for the mailto: protocol association in control panel .
Previously, the ShowComposeNewEmailAsync only works for windows phone runtime app. And it is not up-to-date in the document, because it doesn't include the win 10 support.
On Windows 10 mobile, it works well without any problem. But on Windows Desktop, you have to choose a store app.
This is still an issue in 2019, but I have found a workaround for my project.
I simply assemble an *.msg file with recipients, subject, body, attachments etc. and save it to the apps local cache folder. It can then be launched using Launcher.LaunchFileAsync
As *.msg files are associated with outlook, it will most likely be the default app to open this kind of file. You can create such a file using MsgKit
I have prepared a demo project at: https://github.com/Moolt/UniversialWindowsPlatform.LaunchOutlook

Send a text in message body and not as an attachment

I'm sending the email message from ABAP-report of SAP ECC 6.0 EHP5 to Microsoft Exchange via SMTP. The message reaches user's inbox in Outlook 2013, but it arrives as an attachment instead to be in the body of the message. From the code's point of view, I'm sending the plain text, and I'm expecting to get it inside the message. Since I'm using the default ABAP-approach to sending emails, which sends text inside of an email body, I suppose that the root of the problem is in Exchange/Outlook side.
Is there any Exchange/Outlook setting, which explicitly directs to send the message as an attachment or inside of the message body?
In the examples given, the body is always typed HTM. For the mail body I always use type RAW and this works just fine (with Lotus Notes). So maybe you try the following when creating your mail body:
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = im_text
i_length = txt_len
i_subject = im_subject ).
No, Outlook/Exchange doesn't provide anything for that. I suppose the issue comes from the ABAP/SAP software.

load magento email template

I'm using my own code to send out SMS's to the customers at the same time as the emails go out. I do this by getting the email template code with
$code = $this->getTemplateCode();
and then trying to load the corresponding SMS template with
$sms = $this->loadByCode('sms_'.$code)->getTemplateText();
I then check if $sms is empty before proceeding to send the text, meaning that I can add or remove connected SMS templates at will. The problem I'm having is that I sometimes, when there is no connected "sms_*" template, I get the full email sent out as the SMS instead of no text being sent.
I've debugged the code by sending out the template it tries to load as the actual SMS, and received "sms_creditmemo", but when I instead load it with the method above and do a var_dump($sms); exit;it shows me that it loaded the template "creditmemo_invoice" which is the email template I use instead of "creditmemo" when the payment method is detected. I make sure to use the original template string in $code (used to load SMS template) no matter the payment method.
Now my question would be how this can even be possible, does the loadByCode take best matching template or is there some other more serious bug I've missed, maybe there's better ways to load in the templates and make correct checks to see if they even exist?
I solved this by checking if the correct email template gets loaded with
if ($this->loadByCode($template)->getTemplateCode() == $template)