Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Sending from your pgm

Status
Not open for further replies.

RobCrombie

Programmer
Jun 10, 2001
6
AU
I have been searching for the ' holy grail '

Code that would allow a user of your software, to click a button (or whatever), and send you an email.

I have found various VB pgms that do some of the following.
But no single one that does all of the following.

Opens their default email client (Shell & Mailto)
( thus he/she does not need to know the SMTP server address )
Can handle line breaks in the Body of the email
Can automatically attach a file, when opening the default email client

Has anybody here, seen my ' holy grail '


Just clarifying the above.

Say I develop a pgm and sell it to 50 people.
In the About Dialog, there would be a link to my email address.
If they click that link, then their default email program will open, with most of the fields filled in
(and perhaps with a file attached).
This way the user (of my pgm) does not need to know his/her own SMTP address.
Most eaxampes that I have found, require the user to type his/her own SMTP address, and most would not know it.

Rob
 
Is there an API call to open the default browser? Brett Birkett B.Comp
Systems Analyst
 
yup.

This code does 90% of what I want.

The attachment does not work (Ah! such is life)

The comments in the following are not mine.

Option Explicit

'Fill In the E-Mail Fields
'ShellExecute is one of the most flexible Win32 APIs. Using ShellExecute, you can pass any filename, and if the file’s extension is associated to a registered program on the user’s machine, the correct application opens and the file is played or displayed.
'In the February 1998 101 Tech Tips supplement, Jose Rodriguez Alvira showed ShellExecute’s Internet power ("Create Internet-Style Hyperlinks"). If you pass an HTTP URL, the user’s default 32-bit Web browser opens and connects to the site. If you pass an e-mail address that has been prefaced with "mailto:", the user’s default 32-bit e-mail client opens a new e-mail note with the address filled in.
'
'Here’s how to automatically get a lot more than just the e-mail addresses filled in. If you want to include a list of CC recipients, BCC recipients, or your own subject text or body text, you can create a string variable, add the list of primary addresses (separated by semicolons), then a question mark character and element strings prefaced like this:
'
'For CCs (carbon copies): &CC= (followed by list)
'For blind CCs: &BCC= (followed by list)
'For subject text: &Subject= (followed by text)
'For body text: &Body= (followed by text)
'To add an attachment: &Attach= (followed by a valid file path within chr(34)’s)
'
'To use this trick, create a new VB project, add a form, and add six textboxes and a button (cmdSendIt). Paste this into the form’s Declarations section:
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL = 1

'Paste this code into the button’s Click event:
Private Sub cmdSendIt_Click()

Dim sText As String
Dim sAddedText As String
If Len(txtMainAddresses) Then
sText = txtMainAddresses
End If
If Len(txtCC) Then
sAddedText = sAddedText & "&CC=" & txtCC
End If
If Len(txtBlindCC) Then
sAddedText = sAddedText & "&BCC=" & txtBlindCC
End If
If Len(txtSubject) Then
sAddedText = sAddedText & "&Subject=" & txtSubject
sAddedText = sAddedText & &quot; &quot; & Time '<=== Rob Added thus
End If
If Len(txtBody) Then
sAddedText = sAddedText & &quot;&Body=&quot; & txtBody
sAddedText = sAddedText & &quot; &quot; & Now '<=== Rob Added thus
End If
If Len(txtAttachmentFileLocation) Then
sAddedText = sAddedText & &quot;&Attach=&quot; & Chr(34) & txtAttachmentFileLocation & Chr(34)

''Rob added next 2 lines
' Else
' sAddedText = sAddedText & &quot;&Attach=&quot; & Chr(34) & App.Path & &quot;\TestFile.txt&quot; & Chr(34)


End If
sText = &quot;mailto:&quot; & sText
' clean the added elements
If Len(sAddedText) <> 0 Then
' there are added elements, replace the first
' ampersand with the question character
Mid$(sAddedText, 1, 1) = &quot;?&quot;
End If
sText = sText & sAddedText
If Len(sText) Then
Call ShellExecute(Me.hWnd, &quot;open&quot;, sText, _
vbNullString, vbNullString, SW_SHOWNORMAL)
End If
End Sub

'You can’t have spaces between the ampersands and tags, or between the tags and the equal signs. You don’t have formatting options, so body text will be one paragraph. However, when you use this technique, program errors are e-mailed to you with full details, and you can create real e-mail applets in a just a few seconds. It beats automating a full e-mail program.
'In addition, almost all this functionality is possible in HTML MailTo tags. Here is a sample:
'
'<A HREF=&quot;mailto:smith@smithvoice.com?subject=
'Feedback From VisualBasic ett
'smithvoice.com/vbfun.htm&CC=smith@smithhome.org&BC
'C=fred@fred.net;bill@home.com&body=hello how areyou &quot;>feedback@smithvoice</A>&quot;
'
'I have yet to get HTML to do the attachments, but attachments are no problem in VB.
'Editor’s Note: The full functionality of these extra fields is available in e-mail clients that are totally Exchange-compliant. Some or all of the extra fields might not work with noncompliant e-mail clients.


Rob
rob@crombie.com
 
The only thing I can think of is to ask you what email client you are testing this code with?

&quot;'Editor’s Note: The full functionality of these extra fields is available in e-mail clients that are totally Exchange-compliant. Some or all of the extra fields might not work with noncompliant e-mail clients.&quot;


Brett Birkett B.Comp
Systems Analyst
 
Outlook Express 5.5 SP2

I am using VB6 Pro SP3 in W98 SE

Have you tried the code ?

Did it work for you ?

Rob
 
I had a feeling you were going to say Outlook Express. I am not sure if that would be your problem or not, but I can try the code for you if you like... I am using Outlook 2000.

I'll give it a go for you and let you know.

Cheers. Brett Birkett B.Comp
Systems Analyst
 
With Outlook 2000 you get the error &quot;The command line argument is not valid. Verify the switch you are using.&quot; It turns out that when you comment out the attach part, Outlook opens and starts the new message no problems. I found that if you replace the Chr(34) with single quotes instead, you don't get any errors, but it still won't attach! I'll keep investigating and see what I can find, but it doesn't look like an Outlook Express issue. Brett Birkett B.Comp
Systems Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top