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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to get Visual Basic to send E-mails, please help. 1

Status
Not open for further replies.

GuelphFTC

Programmer
Feb 24, 2006
1
0
0
CA
I have been trying to get a visual basic 6 application to send E-mails.

I have been trying to use MAPI, but it seems to need to log on to an exchange server and my constraints regarding the project prevent me from setting one up.

Any user is only guaranteed to have a working internet connection and windows 2000 or higher.

I need this program to accept user data and then E-mail that data to a hard-coded address. Please advise on whether or not this is possible, and if so, how.

Thanks.
 
Or you could use CDO for Exchange (which doesn't actually need Exchange)
 
We use Catalyst Socket Wrench to send email. It is easy to use and reliable, but it isn't free.
What ever software you choose, be careful about the mime headers you use. If you don't have the right ones with the right format, the email may be dumped as spam.
 
If you would like to continue with MAPI try the following its working reliably for me;

Function DoMAPIemail(MAPISess As Control, MAPIMess As Control, Subject$, MessageText$, AttPaths$(), Optional Recipient$ = "") As Boolean

Dim i%
Dim OrigDir$, Msg$

OrigDir$ = CurDir$
With MAPISess
' XP may need to have a profile set so...
'.LogonUI = False causes problem under XP
.LogonUI = True
.DownLoadMail = False
On Error Resume Next
.SignOn 'changes CurDir$ to MAPI
If Err Then
MsgBox "Error " & Err & " " & Err.Description & " during MAPI Session SignOn"
GoTo exitMapiEmail
End If
On Error GoTo 0
End With

With MAPIMess
.SessionID = MAPISess.SessionID
.Compose
If Len(Recipient$) Then
.RecipAddress = Recipient$
.RecipDisplayName = Recipient$
End If
.MsgSubject = Subject$
.MsgNoteText = MessageText$
For i = 1 To UBound(AttPaths$)
If Len(AttPaths$(i)) Then
.AttachmentIndex = i - 1
.AttachmentPathName = AttPaths$(i)
.AttachmentPosition = i + 1
End If
Next
'by now the mapi controls have set curdir to that of MAPI
' change it back
ChDrive OrigDir$
ChDir OrigDir$
On Error Resume Next
.Send True 'CurDir$ changes to MAPI again
'Error 32001 returned if user cancels send from Outlook
If Err.Number > 0 And Err.Number <> 32001 Then
Msg$ = "Error " & Err.Number & " " & Err.Description & ", sending email" & vbCrLf
If Err = 32003 Then
Msg$ = Msg$ & vbCrLf & "Please start your email program (e.g. Outlook) manually and try again"
End If
MsgBox Msg$, vbCritical
GoTo exitMapiEmail
End If
On Error GoTo 0
End With

DoEvents

MAPISess.SignOff
DoMAPIemail = True

exitMapiEmail:
On Error GoTo 0
ChDrive OrigDir$
ChDir OrigDir$

End Function

This should bring up Outlook or Outlook Express optionally with Recipient, Attachment(s) and Message already filled. The user then can modify and send.

regards Hugh
 
>try the following its working reliably for me

But almost certainly only because you have Outlook or Outlook Express installed and configured. As the OP makes clear they can only guarantee an internet feed and Windows 2000
 
Do a search for 'vbSendMail' in this forum. It's a great dll that's easay to use.

zemp
 
Erm ... that's exactly what gmmastros advised in the very first answer in this thread
 
Sorry to George. I didn't recognize or the check the link first.

zemp
 
With only Windows 2000 and an Internet connection there is nothing you can do.

The user will also have to have at least an accessible SMTP server and account or possibly a webmail account at some accessible web server.

I suppose a third possibility is an accessible server hosted by the application provider, that accepts "mail" and forwards it as conventional email in a "phone home" process.
 
As long as the recipient has a an SMTP gateway (and they all should do ...) you shoud be OK (unless they block senders who don't a PTR record to match their MX record), and you normally won't need an account for that. At least, this is the case for the CDO solution; I can't speak for vbSendMail (but I'd guess it is the same)
 
A lot of "ifs" though... for example many ISPs block port 25 or bounce it to their own SMTP server. A lot depends on the target user base and the network environment they are in.

For general distribution shrink wrapped software I don't see preconfigured emailing as an answer. That may not be an issue for GuelphFTC though.
 
Hi

Have you looked into using Redemption.dll, it bypasses a lot of security flaws.

HTH
 
This isn't a Redemption issue

>A lot of "ifs" though

Well, maybe the the OP can reveal whether they know if SMTP is available to them

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top