-
Local Emailing Without an Email Client
Hi Guys, I have seen various references to vbMailSend.dll, and have taken an interest, I want to incorporate local emailing into an application I am writing, but I havent the foggiest where to start.
the problem is it will need to be compatible with Exchange, or at worst case scenario, I may have to set up an SMTP server, but I really dont want to do this. The other thing is, If I can get away with it I dont want to use a webmail method.
I have read various things about winsocks and SSL, but havent a clue where to start. I downloaded and read the vbSendMail help guide, but short of the first couple of pages that just shows you the working example (and after trying to run the only project that would open and play with a form interface) I am still no wiser. Has anyone any suggestions? if this sendmail is the way to go, can anyone tell me which references need setting up, which of these modules I have downloaded I should be incorporating into the project, and generally if I am in well over my head...
Thanks
J
-
Re: Local Emailing Without an Email Client
Quote:
Hi Guys, I have seen various references to vbMailSend.dll
Did you go thru this link?
http://www.freevbcode.com/ShowCode.Asp?ID=109
-
Re: Local Emailing Without an Email Client
I believe I did yes, (hope thats not considered treason in VBforums ;) )
-
Re: Local Emailing Without an Email Client
Doesn't that work for you.?
-
Re: Local Emailing Without an Email Client
well I did try.
1) the single email example, opened but when i ran the app and tried to connect it timed out, I registered the DLL's but couldnt work out what else needed to be done to it.
2) I tried opening the "vbsendmail.vbp" file, but it opened without a form, and I tried to look through but I couldnt find how I was meant to combine it into my project.
On top of that I tried to look into using it with Exchange, the problem is I cant find out what my pop / smtp settings would be for our local Exchange server, nor do I know if I am looking for something that doesnt exist?
J
-
Re: Local Emailing Without an Email Client
I have seen that there are several posts around this forum, which have been left unanswered, so I am hoping I am not asking for too much. All I want to do is, incorporate the key components into my project, even if I use the "sendMailExample" form and just prefill the boxes and initiate the form.
Is this asking too much do you think?
-
Re: Local Emailing Without an Email Client
check if there is a vbg file, which is a group project and will demonstrate the class
i have used vbsendmail without problem, sending html emails with attachments
you have to specify your smtp server and a few other settings before you can send mail
you can check the server settings in for exchange in outlook or whatever client you use to read your normal mails
comprehensive help files are included, in a word document i think
-
Re: Local Emailing Without an Email Client
I managed to open the example.exe file, and it works with simpleSMTP server on port 25, however I just want to incorporate it into my project. I have opened the vbg file, and had a look and I can see the class files you are referring to, but how do I operate it? am I meant to use the "Send Mail Example" and just manage the text boxes with variables? I have read the documentation that came with it, but I am not quite sure how to follow it.
-
Re: Local Emailing Without an Email Client
you can either include the class files of the sendmail project within your project
which would be compiled within your prgram exe
or
include a reference to the vbsendmail.dll
in this case the vbsendmail.dll would have to be included in your packaging to deploy to other computers
-
Re: Local Emailing Without an Email Client
so if I import the vbg into my current project, and then try to run the form without importing the individual components, that should work?
-
Re: Local Emailing Without an Email Client
If all you want is your app to send mail you ccan use this
I created a module with the following code:
Code:
Imports System.Net.Mail
Public Module SendSMTP
Public Sub SendSMTP(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strBody As String, ByVal strCC As String, ByVal strAttachments As String)
Dim insMail As New MailMessage(New MailAddress(strFrom), New MailAddress(strTo))
With insMail
.Subject = strSubject
.Body = strBody
'.CC.Add(New MailAddress(strCC))
If Not strAttachments.Equals(String.Empty) Then
Dim strFile As String
Dim strAttach() As String = strAttachments.Split(";"c)
For Each strFile In strAttach
.Attachments.Add(New Attachment(strFile.Trim()))
Next
End If
End With
Dim smtp As New System.Net.Mail.SmtpClient
smtp.Host = "{yoursmtpserver}"
smtp.Credentials = New System.Net.NetworkCredential("mysmtpauthusername", "mysmtpauthpass")
smtp.Port = 25
smtp.Send(insMail)
End Sub
End Module
Then add this to your project and i think you get the idea
Code:
SendSMTP.SendSMTP(My.Settings.sms_auth_username, "[email protected]", my subject, mybody, "", "")
I would like to take credit for this if someone else uises it but i got this from a post somewhere online.
Hope this helps
-
Re: Local Emailing Without an Email Client
thanks shapeshift I will probably try that, do I need to include any particular references in the project?
-
Re: Local Emailing Without an Email Client
the is an include. on the module. it is included in the code just copy and paste
if it doesnt work let me know and ill search my refs
-
Re: Local Emailing Without an Email Client
so i dont need to add a reference like I would ActiveX DAO 2.5?
-
Re: Local Emailing Without an Email Client
beat me to an edit post. i dont remember if i had to put in a ref. if it doesnt work let me know and ill search my ref set
-
Re: Local Emailing Without an Email Client
that looks very much like vb.net code, won't work in vb6
a very simple way to send emails is to use cdo.message
you can use createobject("cdo.message")
no references required
do a search in this forum for examples,
will work with secure smtp servers like gmail
-
Re: Local Emailing Without an Email Client
Quote:
Originally Posted by
westconn1
that looks very much like vb.net code, won't work in vb6
Very correct. Sorry didnt even notice "vb6" section
Sorry i couldnt help then.
Cheers
-
Re: Local Emailing Without an Email Client
I thought it might have been vb.net but to be honest I am a pap programmer, so I didnt think to question it! and thanks for that westconn1, I will give that a go later, shapeshift, I will give your code a go when I complete the app and then migrate it to .net after!
-
Re: Local Emailing Without an Email Client
I have just found this code below, but I cannot get it to work... When it opens, I get
"Run Time Error '429':
ActiveX component can't create object
Code:
Private Sub command1_click()
call SendEmail("[email protected]","[email protected]", "test subject", "test email")
end sub
' Sends an email to the appropriate person(s)
'
' SendTo = List of email addresses separated by a semicolon. Example:
' [email protected]; [email protected]; [email protected]
' Subject = Text that summarizes what the email is about
' EmailText = Body of text that is the email
' AttachmentPath = Directory in which the attachment resides
' Attachment = File to send with the email
Sub SendEmail(From As String, SendTo As String, Subject As String, _
EmailText As String, Optional AttachmentPath As String, _
Optional Attachment As String, Optional CC As String)
Const constRoutine As String = "SendEmail"
Dim strSendTo As String
Dim objSendMail As CDONTS.NewMail
Dim i As Integer
On Error GoTo TryMAPI
'Do not cause the user a major error, just log the error and keep going
If SendTo = "" Then Exit Sub
Set objSendMail = New CDONTS.NewMail
With objSendMail
On Error Resume Next
.From = From
If CC <> "" Then
.CC = CC
End If
On Error GoTo ErrorHandler
.To = SendTo
.Subject = Subject
.Body = EmailText
AttachmentPath = Trim$(AttachmentPath)
If AttachmentPath <> "" Then
If Right$(AttachmentPath, 1) <> "\" Then
AttachmentPath = AttachmentPath & "\"
End If
.AttachFile (AttachmentPath & Attachment)
End If
.Send
End With
GoTo ExitMe
TryMAPI:
On Error GoTo ErrorHandler
'If CDO fails, try MAPI
If CC <> "" Then
strSendTo = SendTo & "; " & CC
Else
strSendTo = SendTo
End If
Call SendEmailMAPI(SendTo:=strSendTo, Subject:=Subject, _
EmailText:=EmailText)
ExitMe:
Set objSendMail = Nothing
Exit Sub
ErrorHandler:
Err.Raise Err.Number, Err.Source, Err.Description
Resume ExitMe
End Sub
' Sends an email to the appropriate person(s).
' SendTo = List of email addresses separated by a semicolon. Example:
' [email protected]; [email protected]; [email protected]
' Subject = Text that summarizes what the email is about
' EmailText = Body of text that is the email
' AttachmentPath = Directory in which the attachment resides
' Attachment = File to send with the email
Sub SendEmailMAPI(SendTo As String, Subject As String, EmailText As String, _
Optional AttachmentPath As String, Optional Attachment As String)
Const constRoutine As String = "SendEmailMAPI"
Dim intStart As Integer
Dim strSendTo As String
Dim intEnd As Integer
Dim i As Integer
On Error GoTo ErrorHandler
If frmEmailCommon.MAPISession.SessionID = 0 Then
frmEmailCommon.MAPISession.SignOn
End If
If SendTo = "" Then Exit Sub
With frmEmailCommon.MAPIMessages
.SessionID = frmEmailCommon.MAPISession.SessionID
.Compose
'Make sure that the SendTo always has a trailing semi-colon (makes it
' easier below)
'Strip out any spaces between names for consistency
For i = 1 To Len(SendTo)
If Mid$(SendTo, i, 1) <> " " Then
strSendTo = strSendTo & Mid$(SendTo, i, 1)
End If
Next i
SendTo = strSendTo
If Right$(SendTo, 1) <> ";" Then
SendTo = SendTo & ";"
End If
'Format each recipient, each are separated by a semi-colon, like this:
' [email protected];[email protected]; [email protected];
intEnd = InStr(1, SendTo, ";")
.RecipAddress = Mid$(SendTo, 1, intEnd - 1)
.ResolveName
intStart = intEnd + 1
Do
intEnd = InStr(intStart, SendTo, ";")
If intEnd = 0 Then
Exit Do
Else
.RecipIndex = .RecipIndex + 1
.RecipAddress = Mid$(SendTo, intStart, intEnd - intStart)
.ResolveName
End If
intStart = intEnd + 1
Loop
.MsgSubject = Subject
.MsgNoteText = EmailText
If Left$(Attachment, 1) = "\" Then
Attachment = Mid$(Attachment, 2, Len(Attachment))
End If
If Attachment <> "" Then
If Right$(AttachmentPath, 1) = "\" Then
.AttachmentPathName = AttachmentPath & Attachment
Else
.AttachmentPathName = AttachmentPath & "\" & Attachment
End If
.AttachmentName = Attachment
End If
.Send False
End With
ExitMe:
Exit Sub
ErrorHandler:
Err.Raise Err.Number, m_constPgm & constRoutine, Err.Description
Resume ExitMe
End Sub
-
Re: Local Emailing Without an Email Client
try this
vb Code:
Set objmessage = CreateObject("CDO.Message")
objmessage.Subject = "Example CDO Message"
objmessage.To = "me" ' sent to myself, not at gmail
objmessage.TextBody = "This is some sample message text."
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Your UserID on the SMTP server
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "usernm"
'Your password on the SMTP server
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pass"
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.gmx.com"
'Server port (typically 25)
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
'Use SSL for the connection (False or True)
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = false
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objmessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
objmessage.Configuration.Fields.Update
objmessage.Send
Set objmessage = Nothing
if you are using your default smtp server and do not require username and password the code may be cut down to
vb Code:
Set objmessage = CreateObject("CDO.Message")
objmessage.Subject = "Example CDO Message"
objmessage.To = "me" ' sent to myself, not at gmail
objmessage.TextBody = "This is some sample message text."
objmessage.Send
Set objmessage = Nothing
-
Re: Local Emailing Without an Email Client
Deleted Post as it is no longer relevant.
I have managed to rewrite the code as follows :
Code:
Public Sub SendEmail()
Const cdoSendUsingPort = 2
Const cdoBasic = 1
Set objMessage = CreateObject("CDO.message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "[email protected]"
objMessage.To = "[email protected]"
objMessage.TextBody = "test email"
'SMTP Config
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.yahoo.com"
'Type of authentication, NONE, Basic, (Base64 Encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'Your user ID on the SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]"
'Your password on the SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "tmspassword"
'Server Port, typically 25
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection?
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'connection timeout
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
MsgBox "Done"
End Sub
to be honest, I did find the layout off another site "www.paulsadowski.com/WHS/cdo.htm"
-
Re: Local Emailing Without an Email Client
OK, I dont know if this should or should not be a different thread, but it is from the same problem.
allow me to refer to two seperate internet connections on my site, connection A and Connection B.
Connection A works with the above code, problem free, I have also changed the port (as suggested per Yahoo's FAQ's see here now, Connection A allows me to use this application to send emails via ports 25 and 587.
Connection B on the other hand, wont allow me to send emails via port 25, the port is blocked, most likely by the ISP, so as per advice, I tried to change the port to 587. I also ran a "shields up" check that allowed me to confirm that port 587 is not blocked, but open.
on running the application (whilst trying to email via port 25 or 587!) the following error occurs.
Code:
Run-Time error '-2144220975 (80040213)':
The message could not be sent to the SMTP server. The transport error code was 0x800ccc14. The Server Response was not available.
Now the code has not changed between connections, (I am using virtual pc 2007, and just "swap" the connections to use wireless (connection A a seperate router) and Ethernet (connection B, on my local network, again a completely seperate router from connection A)
What do we think? could this be a simple "ISP" problem, or is there any additional code I need to place in my app?
J
-
Re: Local Emailing Without an Email Client
if the isp has a smtp server, then try using their server on port 25
if they did not have a smtp server they would not block port 25
are you using the same yahoo account for both?
-
Re: Local Emailing Without an Email Client
Yeah, the code doesnt change between the two, its literally I swap the internet accessing connection between connection A and B and the problem appears. Its the fact that it wont work on either port, but both ports are open!
Its baffling me, I just cant find what is blocking it...
-
Re: Local Emailing Without an Email Client
just because the port is open on your computer does not mean it is open on the isp server
did you try sending on the default smtp server?
-
Re: Local Emailing Without an Email Client
not sure what you mean, but I did send it using all the default settings for SMTP on the connection A and B, it worked on A not on B, I also phoned the ISP and they told me they had no blockades in place, unles we specifically requested them, we never have.
-
Re: Local Emailing Without an Email Client
Well I have spoken to the ISP who have said that they do not block port 25, which leaves me to believe that it could be an app, but I am lost completely with it.
-
Re: Local Emailing Without an Email Client
try sending on port 27
i have no idea if this will work, but i have just had a similar issue on a clients machine, and that worked for me, took a while to figure it though
worked on port 25, with one connection, but not another, with same ISP
-
Re: Local Emailing Without an Email Client
Thanks Westconn, unfortunately I have just tried that and it failed to connect to the server again...
-
Re: Local Emailing Without an Email Client
I Have just tried again, but this time bypassed the network, and plugged directly into the router, and it worked, so it seems there is our hardware firewall that is blocking the connection. Port 25 however is completely open, so is there anything else I need to configure on a firewall for this to work?
to be honest it just works fine otherwise, but when I use the code to connect to the server, does traffic head straight to port 25 or does it hit anything else before hand??? i.e.
Code:
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "smtppassword"
Does it travel via HTTP first before it tries to connect via port 25, as I cannot make this work, the port is open, but the app wont work!!
Also does anyone know if it has a different "source port" and if so, is it different per machine?
J