Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert signature to email via visual basic for application

Posted on 2006-06-20
13
Medium Priority
?
284 Views
Last Modified: 2013-11-25
I like to insert a signature (name, telefon, ... not signature like certifcate) in a email via visual basic for application
0
Comment
Question by:ibeling
  • 5
  • 3
  • 2
13 Comments
 
LVL 21

Expert Comment

by:alainbryden
ID: 16943530
If you are sending through another email client, Only the email client can define a reoccuring signature. If you wish to add a signature, than you must concatonate whatever the signature is supposet to be to the end of the message. So;

message As String
signature As String
message = message & vbNewLine & vbNewLine & signature
0
 
LVL 10

Expert Comment

by:cool12399
ID: 16944648
are you actually writing an e-mail application? or you mean just appending a signature?
if the latter, yes, simply take your message, append the signature, and then pass the new
message to your procedure.
0
 

Author Comment

by:ibeling
ID: 16949007
I have already some signature defined in Outlook. (ones for internal use, ones for external, ones for private). So maybe my question should be more "how can i access the signature collection" ...
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 21

Expert Comment

by:alainbryden
ID: 16951584
No. The way outlook inserts a signature is to take the stored signature and code it directly into the html of the email, so the only way you can insert the signature is to do the same. There is no field such as OutlookApp.signature("Name") or anything like that that you can use.

As for where outlook stores it, all signatures are stored in HTML, Rich Text AND .txt format under

 C:\Documents and Settings\[username]\Application Data\Microsoft\Signatures

So if you know the name of the signature. You can concatonate as follows.

Open up C:\Documents and Settings\[username]\Application Data\Microsoft\Signatures\myName.txt (or .htm or .rtf )
Copy Everything
Paste it into your message.
This can easily be automated, let me know if you can't figure it out.
0
 

Author Comment

by:ibeling
ID: 16951637
It will help me to save time if you can make a little code snippet, to start.

Thanks
0
 
LVL 21

Expert Comment

by:alainbryden
ID: 16951745
Well I have no idea how you're writing you email in Visual basic, but to access that file you say:

dim SIGNATURE As String, text As String, _
       SignatureName As String, Username As String
username =  'Fill this in yourself
SignatureName =  Name 'Fill this in yourself

Open "C:\Documents and Settings\" & Username & "\Application Data\Microsoft\Signatures\" & SignatureName & ".txt" For Input As #1

SIGNATURE = vbNullString
Do While Not EOF(1)
    Line Input #1, text
    SIGNATIRE = SIGNATURE & vbNewLine & text
Loop
Close #1   'Closes the signature file you opened

'At this point you have the entire signature stored as a string (SIGNATURE). Do with it what you will. Attatch it to the end of the message is probably the best thing.

MessageTextBox.text = MessageTextBox.text & vbNewLine & SIGNATURE

'Now send the message, complete with signature and all.
0
 
LVL 10

Expert Comment

by:cool12399
ID: 16953606
If you need outlook code, take a look here:
http://www.outlookcode.com/
0
 

Author Comment

by:ibeling
ID: 16953755
We generate Emails from a application.
Depend of the system variable USERNAME, we want add his signature.
Yes it is strange. But the customer wishes are our job.
Thanks for help.

Regards Ingo
0
 
LVL 21

Accepted Solution

by:
alainbryden earned 2000 total points
ID: 16953996
Well ibeling, according to your description the solution is this:

dim SIGNATURE As String, text As String, _
       SignatureName As String, Username As String

SignatureName = 'SEE BELOW

Open "C:\Documents and Settings\" & USERNAME & "\Application Data\Microsoft\Signatures\" & SignatureName & ".txt" For Input As #1

SIGNATURE = vbNullString
Do While Not EOF(1)
    Line Input #1, text
    SIGNATIRE = SIGNATURE & vbNewLine & text
Loop
Close #1   'Closes the signature file you opened

'Attatch the signature


What that code will do is locate the signature, and copy it to that string SIGNATURE, then you need to take that string and append it to the end of the email message. I know you can do that on your own.


The only problem now is how do you get the SignatureName? This is almost always called "Name.txt" But the user is able to rename his signatures and have more than one. The only solution is to let the user browse and select a user name. Do to that you need to add In Project components the Windows Common Dialog Control, and drag one onto your form, and name it "FileDialog".

Once you do this add these lines of code before my code:

   Dim SignatureLocation

    FileDialog.DialogTitle = "Load A Signature"
    FileDialog.DefaultExt = "txt"
    FileDialog.Filter = "Text Documents (*.txt)|*.txt"
    FileDialog.Flags = &H1004 ' This flag means only existing names are allowed and no read-only
    FileDialog.InitDir = "C:\Documents and Settings\" & Username & "\Application Data\Microsoft\Signatures\"
    FileDialog.ShowOpen     'User selects the file to open

    Open FileDialog.FileName For Input As #1

And then the rest of the code is the same and you will have their signature. Try it out. You will see it works 100%. I already tested it myself. If you want, you can store this signature so that they only have to load it once and then it always uses the same signature again. I'm sure you can handle this much.


Enjoy.
0
 
LVL 21

Expert Comment

by:alainbryden
ID: 17293295
once taking reccomendations, if a response isn't given, I would like to suggest that I gave a working solution.

Alain
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question