Hi all,
Before I ask this question I would like to do a search for the answer but the search facility is down at the moment so I don't have that luxury. I am trying to send email from VB. I am using an SMTP mail object to do so. The following is the code
On the techsupport account that this email is directed too an auto response has been set up. However when a mail is sent to the tech account using this procedure in VB, the mail arrives but the autoresponse dosn't get back through. Where as if a mail is sent to the tech account as normal (i.e. not through this procedure in VB) the autoresponse gets back with no problems. I have contacted the provider of the mail server and they are convinced the problem is with my code. Can anyone offer a suggestion as to the cause of this problem or better still, a solution!
I have also looked up a faq - - on sending email throught VB and tried the code provied there but I can't seem to get it working. I get the error "user type not defined" for MAPI.Session but i have referenced both the CDO object and the outlook object in my references.
Can anyone help?
Erin
Before I ask this question I would like to do a search for the answer but the search facility is down at the moment so I don't have that luxury. I am trying to send email from VB. I am using an SMTP mail object to do so. The following is the code
Code:
Public Sub SendMail()
On Error GoTo SendMailErr
'We declare variables as
Dim mail As New SMTP
Dim msg As New Message
Dim res As Integer
Dim html_msg As String
Dim result As String
'When ThrowErrors is True, any non-success return code will cause ZMail to generate an COM exception that contains the relevant error message. This type of exception will cause a VB or VBScript program to immediately stop executing and display the message and line number that generated it. This is extremely handy for debugging but should not be used in production.
msg.ThrowErrors = True
'Specifying sender name and email as you want it appear in message header:
res = msg.AddHeader(HEADER_FROM, txtFrom.text)
'Specifying the recipient name and his email:
res = msg.AddHeader(HEADER_TO, txtTo.text)
'Specifying the message subject:
res = msg.AddHeader(HEADER_SUBJECT, txtSubject.text)
result = gblErrorMessage
'Composing body for our test html message:
'html_msg = txtBody.text & vbCrLf & vbCrLf & _
' "Project Name = " & txtProject.text & vbCrLf & _
' "Record Name = " & txtRecord.text & vbCrLf & vbCrLf & _
' "Observations: " & txtObservations.text
html_msg = result
'and adding it:
res = msg.AddText(TEXT_HTML_TEXT, html_msg)
'In order to send email you need to specify correct SMTP server:
mail.SMTPServer = MAILSERVER
'and sender address:
mail.SenderAddress = senderAddress
'Final step is sending message thru mail object:
mail.Add msg, mailobject
End Sub
On the techsupport account that this email is directed too an auto response has been set up. However when a mail is sent to the tech account using this procedure in VB, the mail arrives but the autoresponse dosn't get back through. Where as if a mail is sent to the tech account as normal (i.e. not through this procedure in VB) the autoresponse gets back with no problems. I have contacted the provider of the mail server and they are convinced the problem is with my code. Can anyone offer a suggestion as to the cause of this problem or better still, a solution!
I have also looked up a faq - - on sending email throught VB and tried the code provied there but I can't seem to get it working. I get the error "user type not defined" for MAPI.Session but i have referenced both the CDO object and the outlook object in my references.
Can anyone help?
Erin