Skip to main content
Inspiring
July 11, 2014
Beantwortet

Can you attach a select file into a mail in “Outlook” then send to a specify address?

  • July 11, 2014
  • 9 Antworten
  • 1947 Ansichten

I have been looking around and trying to find ways to do the following with extendscript:

1. Open ‘Outlook’

2. Create a new mail

3. Attach the files which was selected to a mail then send to a specify address

Is this possible?

I found this that dose it for MAC but I need to do it in a windows platform

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von Trevor:

Hi John

Well not a very inDesign question is it but this will do what you want.

// Send selected files as attachments through outlook on windows 

// By Trevor htps://forums.adobe.com/message/6546861#6546861

// Need a custom script , willing to pay for it send me a private message.

var notify = true; // set to true if you want a popup measage to say that the mail is sending

var delay = 1.5 // the number of seconds you want the popup to appear

var ToAddress = "Barack@White-house.org"; // You might need to change this 

var MessageSubject = "Howdy Barack, take a look at this"; // You might need to change this

// bodyText set at line 27 Below

var myAttachments =  File.openDialog ("Select the files you wish to attach", "All Files: *.*", true);

if (!myAttachments) {

    alert("Sorry mate I can't send your attachments if you don't select them\rPlease try again next year\rThanks");

    exit();

}

var n, MessageAttachments = [], bodyFileNames = [], fName = "";

for (n = 0; n < myAttachments.length; n++) {

    fName = myAttachments.fsName;

    MessageAttachments = 'newMail.Attachments.Add("' + fName + '")';

    bodyFileNames = fName;

}

MessageAttachments = MessageAttachments.join("\r") + "\r";

bodyFileNames = bodyFileNames.join("\" & vbNewLine & \"");

    // the \" & vbNewLine & \" is a way off putting in line feads

MessageBody = "Howdy i spent yonks of time making this. \" & vbNewLine & \"" + bodyFileNames; // You might need to change this

//VBS code very very very heavily based on the answer of ShaddowFox333 http://www.tek-tips.com/viewthread.cfm?qid=728333 

myVBS = '''Dim ToAddress

Dim FromAddress

Dim MessageSubject

Dim MessageBody

Dim MessageAttachment

Dim ol, ns, newMail

ToAddress = "''' + ToAddress + '''"

MessageSubject = "''' + MessageSubject + '''"

MessageBody = "''' + MessageBody + '''"

Set ol = CreateObject("Outlook.Application")

Set ns = ol.getNamespace("MAPI")

Set newMail = ol.CreateItem(olMailItem)

newMail.Subject = MessageSubject

newMail.Body = MessageBody & vbCrLf

newMail.RecipIents.Add(ToAddress)

''' +

MessageAttachments + "newMail.Send";

try {

    app.doScript (myVBS, ScriptLanguage.VISUAL_BASIC, undefined, UndoModes.AUTO_UNDO);

    if (notify) {

        var tempFile = new File (Folder.temp + "/" + +new Date + ".vbs");

        tempFile.open('w');

        tempFile.write('''Set shell = CreateObject("Wscript.Shell")

                    delay = ''' + delay + '''

                    shell.Popup "Sending document by outlook", delay, "InDesign Mail Manager", 64

                    Set fso = CreateObject("Scripting.FileSystemObject")

                    fso.DeleteFile("''' + tempFile.fsName + '''"),DeleteReadOnly

                    ''');

        tempFile.close();

        tempFile.execute();

    }

}

catch (e) {alert ("Drat goofed up")}

Trevor

OTT: Congrats Uwe

9 Antworten

Inspiring
July 18, 2014

Hi, Trevor

I feel sorry to tell you, the mac use quick key send email

by use this kind of software,

Startly - QuicKeys 4 for Mac OS X

called "QuicKeys 4 for Mac OS X"

and win 7 also has this vesion of Quickeys:

Startly - QuicKeys 3 for Windows Frequently Asked Questions

thank you for your help, appreciate!

John

Inspiring
July 17, 2014

Hi, Trevor

thank you for your help, thank very much!

John

Inspiring
July 17, 2014

Hi, Trevor

you mean, I have to put in indesign?

ok got it

but not really, convenient

what if other kind of file like work or excel, or power point, not need to open indesign?

John

Trevor:
Legend
July 17, 2014

Well this is an InDesign scripting forum!

The solution is very simple. I'll try post it in the next few of days

Inspiring
July 17, 2014

Hi, Trevor

I don't how use the script,

where I can put the script into

how to set a shortcut for it

I know how to change the mail address and the massage, but I don't know how to use it

thanks

Best regard

Join

Inspiring
July 14, 2014

but I don't have a paypal account!

Trevor:
Legend
July 14, 2014

I did write you don't need a PayPal account

I meant to write (NO PayPal account needed)

You DO need a credit card so you use it with PayPal and they pay me.  If you don't have one then you'd have to pay strait into my bank account which is a bit more complicated.

Click here and you will get this screen, click the the Don't have a PayPal account option and fill in the details

After you've filled in all the details I shall be 1 GBP better off and we will know that you can make the payment.

Inspiring
July 13, 2014

Hi, Trevor

like this:

I just want to send what I selected by a short cut, and no need to type in mail address and message every time.

John

Trevor:
Trevor:Antwort
Legend
July 13, 2014

Hi John

Well not a very inDesign question is it but this will do what you want.

// Send selected files as attachments through outlook on windows 

// By Trevor htps://forums.adobe.com/message/6546861#6546861

// Need a custom script , willing to pay for it send me a private message.

var notify = true; // set to true if you want a popup measage to say that the mail is sending

var delay = 1.5 // the number of seconds you want the popup to appear

var ToAddress = "Barack@White-house.org"; // You might need to change this 

var MessageSubject = "Howdy Barack, take a look at this"; // You might need to change this

// bodyText set at line 27 Below

var myAttachments =  File.openDialog ("Select the files you wish to attach", "All Files: *.*", true);

if (!myAttachments) {

    alert("Sorry mate I can't send your attachments if you don't select them\rPlease try again next year\rThanks");

    exit();

}

var n, MessageAttachments = [], bodyFileNames = [], fName = "";

for (n = 0; n < myAttachments.length; n++) {

    fName = myAttachments.fsName;

    MessageAttachments = 'newMail.Attachments.Add("' + fName + '")';

    bodyFileNames = fName;

}

MessageAttachments = MessageAttachments.join("\r") + "\r";

bodyFileNames = bodyFileNames.join("\" & vbNewLine & \"");

    // the \" & vbNewLine & \" is a way off putting in line feads

MessageBody = "Howdy i spent yonks of time making this. \" & vbNewLine & \"" + bodyFileNames; // You might need to change this

//VBS code very very very heavily based on the answer of ShaddowFox333 http://www.tek-tips.com/viewthread.cfm?qid=728333 

myVBS = '''Dim ToAddress

Dim FromAddress

Dim MessageSubject

Dim MessageBody

Dim MessageAttachment

Dim ol, ns, newMail

ToAddress = "''' + ToAddress + '''"

MessageSubject = "''' + MessageSubject + '''"

MessageBody = "''' + MessageBody + '''"

Set ol = CreateObject("Outlook.Application")

Set ns = ol.getNamespace("MAPI")

Set newMail = ol.CreateItem(olMailItem)

newMail.Subject = MessageSubject

newMail.Body = MessageBody & vbCrLf

newMail.RecipIents.Add(ToAddress)

''' +

MessageAttachments + "newMail.Send";

try {

    app.doScript (myVBS, ScriptLanguage.VISUAL_BASIC, undefined, UndoModes.AUTO_UNDO);

    if (notify) {

        var tempFile = new File (Folder.temp + "/" + +new Date + ".vbs");

        tempFile.open('w');

        tempFile.write('''Set shell = CreateObject("Wscript.Shell")

                    delay = ''' + delay + '''

                    shell.Popup "Sending document by outlook", delay, "InDesign Mail Manager", 64

                    Set fso = CreateObject("Scripting.FileSystemObject")

                    fso.DeleteFile("''' + tempFile.fsName + '''"),DeleteReadOnly

                    ''');

        tempFile.close();

        tempFile.execute();

    }

}

catch (e) {alert ("Drat goofed up")}

Trevor

OTT: Congrats Uwe

Inspiring
July 14, 2014

Hi, Trevor

appreciate for help, but how can use it?

Inspiring
July 11, 2014

myVBS = '''Dim ToAddress 

Dim FromAddress 

Dim MessageSubject 

Dim MessageBody 

Dim MessageAttachment 

Dim ol, ns, newMail 

ToAddress = "''' + ToAddress + '''" 

MessageSubject = "''' + MessageSubject + '''" 

MessageBody = "''' + MessageBody + '''" 

MessageAttachment = "''' + MessageAttachment + '''" 

Set ol = CreateObject("Outlook.Application") 

Set ns = ol.getNamespace("MAPI") 

Set newMail = ol.CreateItem(olMailItem) 

newMail.Subject = MessageSubject 

newMail.Body = MessageBody & vbCrLf 

newMail.RecipIents.Add(ToAddress) 

newMail.Attachments.Add(MessageAttachment) 

newMail.Send 

How can I add a function to send my select files?

Trevor:
Legend
July 13, 2014

Hi John

I'm a bit confused, the script I put over there does not generate files it just sends the active document as an attachment

If you want to send some different file as an attachment just change line 17 from


var MessageAttachment = doc.fullName.fsName

to

var MessageAttachment = myFile.fsName

where myFile is defined as your file. For example myFile = File("C:/document1234.indd") or one can just use

var MessageAttachment = "C:/document1234.indd"


HTH


Trevor

Inspiring
July 13, 2014

Hi Trevor,

Sorry, I just want to send selected file, not the open file, is that posible?

thanks

John

Inspiring
July 11, 2014

but I not need to gen anything, can you help me to change the function of send only?

Chinnadk
Legend
July 11, 2014