PDA

View Full Version : Solved: SMTP & Excel



CBrine
11-29-2006, 07:19 AM
I got this code from someone on this board, can't remeber who I recieved it from. It works great, but I haven't used it for any business application, since it looks like it bounces the mail I sent through the microsoft SMTP. Something outside of my scope of control. I can change it to take a login to our SMTP site, but that would require me to add my username and password to the code, which I don't want to do.
I've found a vb DLL class that does something similiar, where it sends the SMTP mail without a password. I want to use that, but my concern is that since it doesn't require a user/password that it may also be bouncing off an outside SMTP server.
My question is, If my server requires a user/password, is it possible that the dll could bypass this using a different technique?(It mentions encapsulating it using WinSock) Or if it's not using the user/password, then it must be bouncing through another STMP server.

Any help is appreciated.

Sub Mail_Small_Text_CDO()
Dim iMsg As CDO.Message
Dim iConf As CDO.Configuration
Dim flds As Object
Dim strbody As String
' Dim Flds As Variant

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

iConf.Load -1 ' CDO Source Defaults
Set flds = iConf.Fields
With flds
'.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "111.111.111.111"
'.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'.Update

.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "111.111.111.111"
.Item(cdoSMTPAuthenticate) = 1
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Update
End With

strbody = "Hey There," & vbNewLine & vbNewLine & _
"Test 1" & vbNewLine & _
"Test 2" & vbNewLine & _
"Test 3" & vbNewLine & _
"Test 4"

With iMsg
Set .Configuration = iConf
.To = "WhoEver@where.com"
.CC = ""
.BCC = ""
.From = """ME"" <me@where.com>"
.Subject = "Important message"
.TextBody = strbody
.Send
End With

Set iMsg = Nothing
Set iConf = Nothing
End Sub

Thanks
Cal

PS- I've cross posted this at
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_22076337.html
since I'm not sure the expertise is here to answer this one.

Bob Phillips
11-29-2006, 09:04 AM
Why don't you create a VB DLL that handles the sending, you can have the password in there and it would then be hidden.

Failing that you could mail Ron and see if he knows how.

CBrine
11-29-2006, 09:18 AM
I've done a little research and learned a few new things on SMTP. I believe the class works by using winsock to telnet to the SMTP server. I was able to manually complete the process of sending an actual email to myself using telnet and my SMTP server. When I reviewed the classes .send method I was able to see the same process in the code as I used to manually send the mail.

Bottom line is that it looks like I'm able to send an email using our local SMTP server(I think it validates that the mail is sent from an internal IP), without using my user/password combination. So, it looks like the class is OK.

Cal

xld,
I'm not so concerned with my user/password in the code, as I am with having to force change my password every 90 days, required by our Dallas office. This would be a major pain in the A$$. Looks like I'm OK for the class though.

Thanks

Ken Puls
11-29-2006, 10:06 AM
Hey guys,

This is interesting. I knew that there must be a way to send mail via CDO where the server requires authentication. I'd never found it though. Thanks for that, Cal!

Works with either the server IP or the server name too. Very nice! :)