I'd like to send and email with apple script to do like this :
hi,
here is the attachment file
[The attachment.pdf]
As you can see, it is a good attachment
Thanks
Bye
I know how to use applescript to send an email with attachment at the end of the message, but not between 2 sentences.
I tried something like this, but it doesn't work :
set _attachment to "Macintosh HD:Users:usr:Desktop:Form.pdf"
set msg to make new outgoing message with properties {visible:true, subject:"Here it is", content: "hi,
here is the attachment file"}
tell msg to make new attachment with properties {file name:_attachment as alias}
tell msg to add "As you can see, it is a good attachment
Thanks
Bye" as content
Thanks you all for your support.
Dam
Assuming we are talking about Apple Mail, you can specify the location of the attachment in the content of the message.
The text of body is passed instantly and the attachment is inserted afterwards.
set _attachment to (path to desktop as text) & "Form.pdf"
tell application "Mail"
set msg to make new outgoing message with properties {visible:true, subject:"Here it is", content:"hi,
here is the attachment file
As you can see, it is a good attachment
Thanks
Bye"}
tell content of msg to make new attachment with properties {file name:_attachment as alias} at after third paragraph
end tell
Related
I have an AppleScript which starts a new email in Mail, and fills in the Body with the contents of a user-selected file.
The problem is that the first line of the body in the new email is always blank -- i.e. there's a line-break before the body from the user-selected file. No matter what I do, even if I hardcode the body into the script (e.g. "Hello world!") it starts on the second line of the email.
Can anyone please suggest a way to fix this?
property theToAddress : "john#example.com"
property theSubject : "Example subject"
set theTo to theToAddress
set theSubjectLine to theSubject
set theBody to choose file with prompt "Please select a file for the body of the email:"
set theMessageBody to read theBody as «class utf8»
tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubjectLine, content:theMessageBody, visible:true}
tell theNewMessage
make new to recipient with properties {address:theTo}
end tell
end tell
I am running some applescript. The purpose is to open Mac Mail and create a new message with an attachment that is located on the users' desktop.
It IS currently working, BUT ... the attachment is being inserted AFTER the email signature and we need the attachment to be located in front of the email signature (at the beginning of the email).
thank you in advance for any help you can provide!
Code is below ...
set theAttachment to "{theDesktopPath and file name}"
set RecipientAddress to "joe#joe.com"
set RecipientName to "Joe"
set TheSubject to "Estimate"
tell application ”Mail”
set newMessage to make new outgoing message with properties {subject:theSubject, visible:true}
tell newMessage
make new to recipient with properties {name:recipientName, address:RecipientAddress}
tell content of newMessage
make new attachment with properties {file name:theAttachment as alias} at after the last paragraph
end tell
end tell
activate
end tell
Change "after the last" to "before the first" like so:
set theAttachment to "{theDesktopPath and file name}"
set RecipientAddress to "joe#joe.com"
set RecipientName to "Joe"
set TheSubject to "Estimate"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:TheSubject, visible:true}
tell newMessage
make new to recipient with properties {name:RecipientName, address:RecipientAddress}
tell content of newMessage
make new attachment with properties {file name:theAttachment as alias} at before the first paragraph
end tell
end tell
activate
end tell
Is there a way to delete mails by the subject, i'm trying to make an applescript that deletes mails with a certain subject from my 'Sent' mailbox. I have tried these scripts this with a test mail:
tell application "Mail"
set theMails to every message of (every mailbox whose name is "Sent") whose subject is "Test Mail"
delete theMails
end tell
and:
tell application "Mail"
set theMails to {every message of inbox "Sent" whose subject is "Test Mail"}
delete theMails
end tell
Both scripts didn't work, and I didn't understand the returned errors so I could not find a solution. Help appriciated!
the code bellow works. better to use word "contains" instead of trying exact match of the subject
tell application "Mail"
set theMails to {every message of sent mailbox whose subject contains "Test Mail"}
delete theMails
end tell
I've a custom form (created with form API) that need send an uploaded file by email. The current form submit handler sends the email without attachment using drupal_mail().
So I'm looking for a solution to properly send email with attachment from Drupal. Mime Mail seems an overkill because HTML mail, templating and its other features are not required. But the only other alternative I see is to set the appropriate headers and serialize the attached file in the mail body when processing the mail in my hook_mail() implementation.
Did I miss anything? Is there any module to handle this?
Mimemail is the easiest solution here. Be it an overkill or not, it will allow you to get it done with a single function call.
If you insist, you may have your homemade attachment sender: base64 encode your attachment(s), add them to the mail body, add the correct headers and you're done.
You can use mime mail and force the message body to be sent in plaintext format. Here is an excerpt from the module's readme file:
USAGE
This module may be required by other modules, but is not terribly
useful by itself. Once installed, any module can send messages by
calling the mimemail() function:
$sender - a user object, text email address or an array with name, mail
$recipient - a user object, text email address or an array with name, mail
$subject - subject line
$body - body text in HTML format
$plaintext - boolean, whether to send messages in plaintext-only (default FALSE)
$headers - a keyed array with headers (optional)
$text - plaintext portion of a multipart e-mail (optional)
$attachments - array of arrays with the file's path, MIME type (optional)
$mailkey - message identifier
return - an array containing the MIME encoded message
The key thing being to set the $plaintext argument to TRUE. Now you can have your cake and eat it too.
You could always have a look at the Swift Mailer module which lets you send HTML (MIME) e-mails, e-mails with inline images and e-mails with attachments. It is also cabable of automatically generating plain text versions based on the HTML e-mail version, which in the end will let the user's e-mail client display the preferred version (HTML or plain text).
The Swift Mailer module is available on http://drupal.org/project/swiftmailer.
For the record : I'm the author and maintainer of the module.
The Webform module allows you to create a form and has a file option which can be used as an attachment. All available form components are listed on the module's manual page.
Once installed Webform will appear as a content type. Once you have saved the fundamentals, such as the title and the email to address, you will have the ability to add the required form components.
Add a component of type 'file', ensuring the 'email' (to recipient) option is ticked, and you will then be able to customize the permitted file types, extensions, sizes and upload folder.
You could use the Zend Framework.
function sendEmail($params){
ini_set('include_path', 'inc/');
require_once ('inc/Zend/Mail.php');
$mail = new Zend_Mail();
$mail->setSubject( $params['subject'] );
$mail->setBodyText( $params['bodyText'] );
$mail->setBodyHtml( $params['bodyHtml'] );
$mail->setFrom( $params['fromEmail'], $params['fromName'] );
$mail->addTo( $params['toEmail'], $params['toName'] );
// Finally, add an attachment
assert( file_exists($params['attachFile']) );
$at = $mail->addAttachment(file_get_contents($params['attachFile']));
$at->type = $params['attachType'];
$at->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$at->filename = $params['attachName'];
$mail->send();
}
I'm creating an email message using CDO object (and VB6, but that doesn't really matter).
With New CDO.Message
.To = "<address>"
.Subject = "Manifest test 8"
.Organization = "<company>"
.From = "<address>"
.Sender = .From
With .Configuration
.Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
.Fields(cdoSMTPServer).Value = "192.168.0.4"
.Fields.Update
End With
With .AddAttachment("c:\import\customermanifestOURACCOUNT11122008110032.dat")
.Fields(cdoContentDisposition).Value = "attachment; filename=""Consignor.dat"""
.Fields.Update
End With
.Send
End With
As you can see, the message is empty and contains an attachment that I rename in the email.
The attachment is an ASCII text file, fixed-width, that contains some output from our systems, one record per line, separated with CRLF.
When the message gets sent, all CRs get stripped out the attachment, so the receiver gets a file that only has LFs and therefore is corrupted.
I tried to change ContentEncoding to 7bit and base64, didn't work.
I tried to set ContentMediaType for the attachment to text/plain, didn't work.
I tried to not rename the attachment after adding, didn't work.
The ContentMediaType for the attachment is set to application/octet-stream by default, so I can't figure out why (and by what) it gets changed in the first place.
If I execute .SaveToFile() on the attachment right after .Send(), it saves valid file on the disk.
Is this a problem in my code, or is it a mail server setting or something?
Ok, that was weird.
We used our gmail accounts to test that thing, more specifically, gmail web interface. We clicked attachments links to save reveived files. And the files were corrupted.
As soon as we instead tried some thick clients, it turned out to be fine. All files get download properly without any corruptions.
So I assume this is a bug in gmail web interface (as opposed to gmail POP3 interface).
I have not used CDO in a long time, but i remember having this issue in the past. By trying different things, we figured that if there was any content in the body of the message the attachments were sent properly.
Weird, i know.
try it and let us know.
I just got this same trouble. I switched to Jmail and my CSV (text file) was now exactly like the original when I read it from gmail.
I compared the original message (in Gmail, option - view original message) and discovered that with CDO.Message, the attachment is not encoded really well, it is kept in text format, and the mail client do what he wants with it. With Jmail, the message is encoded in Base64 so it is kept in its original state from the start to the end. So, be careful when using CDO.Message with text file attachments! Try using Jmail (free) instead.
CDO.message: Content-Transfer-Encoding: quoted-printable
Jmail.message: Content-Transfer-Encoding: base64