E
Eka1618
Hello,
I am trying to use some code that I got from Microsoft. I want to send an
e-mail without editing it first. I was using 'SendObject' but I got the error
message from outlook saying "A program is trying to send an e-mail on your
Behalf."
I researched this and I have now changed to a new method. When I use the new
code, I was getting an error about being unable to connect to the server,
then it went away. So now it seems as if my code works but it is skipping the
part where it sends the e-mail (the with iMsg loop). I do not know if I even
have the correct server name, and I am having a hard time trying to find out
what it is.
The following is my code:
Private Sub btnAccept_Click()
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim emName As String, varItem As Variant
Dim emailBody As String
Const cdoSendUsingPort = 2
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"mcg144.NTDOMAIN.COM"
..Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 10
.Update
End With
Me.REQUEST_NO.SetFocus
emailBody = "Hello," & vbCrLf & vbCrLf & _
"The product test request for Request Number: " & REQUEST_NO.Text & _
" has been Accepted by the Tech Team Leader." & vbCrLf & vbCrLf & _
"To review the status of this product test request, " & _
"Please log into the Product Engineering Database, and view the status
on the Test Queue Screen." & vbCrLf & vbCrLf & _
"Thank You!"
' Apply the settings to the message.
' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<b>" & emailBody & "</b></br>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"
If Me.lboRequestor.ItemsSelected.Count = 0 Then
MsgBox "Please select a test requestee"
Exit Sub
End If
For Each varItem In Me.lboRequestor.ItemsSelected
emName = emName & Chr(34) & lboRequestor.Column(2, varItem) & Chr(34) &
","
Next varItem
'remove the extra comma at the end
'add the requestor to the e-mail list recipients
emName = Left$(emName, Len(emName) - 1)
With iMsg
Set .Configuration = iConf
.To = emName 'ToDo: Enter a valid email address.
.From = "(e-mail address removed)" 'ToDo: Enter a valid email address.
.Subject = "Test Request Accepted (Requestor next action required)"
.HTMLBody = strHTML
.Send
End With
' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
MsgBox "Mail Sent!"
If anyone has any suggestions on what do do please let me know. Also, I
would prefer to use my old method of 'SendObject', so if anyone knows how to
get rid on the "On Behalf" message using while using 'SendObject,' please let
me know, Thank You!
I am trying to use some code that I got from Microsoft. I want to send an
e-mail without editing it first. I was using 'SendObject' but I got the error
message from outlook saying "A program is trying to send an e-mail on your
Behalf."
I researched this and I have now changed to a new method. When I use the new
code, I was getting an error about being unable to connect to the server,
then it went away. So now it seems as if my code works but it is skipping the
part where it sends the e-mail (the with iMsg loop). I do not know if I even
have the correct server name, and I am having a hard time trying to find out
what it is.
The following is my code:
Private Sub btnAccept_Click()
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim emName As String, varItem As Variant
Dim emailBody As String
Const cdoSendUsingPort = 2
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") =
cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"mcg144.NTDOMAIN.COM"
..Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 10
.Update
End With
Me.REQUEST_NO.SetFocus
emailBody = "Hello," & vbCrLf & vbCrLf & _
"The product test request for Request Number: " & REQUEST_NO.Text & _
" has been Accepted by the Tech Team Leader." & vbCrLf & vbCrLf & _
"To review the status of this product test request, " & _
"Please log into the Product Engineering Database, and view the status
on the Test Queue Screen." & vbCrLf & vbCrLf & _
"Thank You!"
' Apply the settings to the message.
' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<b>" & emailBody & "</b></br>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"
If Me.lboRequestor.ItemsSelected.Count = 0 Then
MsgBox "Please select a test requestee"
Exit Sub
End If
For Each varItem In Me.lboRequestor.ItemsSelected
emName = emName & Chr(34) & lboRequestor.Column(2, varItem) & Chr(34) &
","
Next varItem
'remove the extra comma at the end
'add the requestor to the e-mail list recipients
emName = Left$(emName, Len(emName) - 1)
With iMsg
Set .Configuration = iConf
.To = emName 'ToDo: Enter a valid email address.
.From = "(e-mail address removed)" 'ToDo: Enter a valid email address.
.Subject = "Test Request Accepted (Requestor next action required)"
.HTMLBody = strHTML
.Send
End With
' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
MsgBox "Mail Sent!"
If anyone has any suggestions on what do do please let me know. Also, I
would prefer to use my old method of 'SendObject', so if anyone knows how to
get rid on the "On Behalf" message using while using 'SendObject,' please let
me know, Thank You!