If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#21
|
|||
|
|||
Hi,
I would like to do the same thing using VB .Net. Is there an alternative to using winsock in .Net? Maybe a simpler way of creating a VB .Net mail application that would do the same thing without the winsock DataArrival. Thanks, Mangi. "Ron Weiner" wrote: Brad If your clients are Win2K or later you might want to consider sending mail Via Microsoft CDO. Here is some sample code to get you started. Public Sub testCDO() ' Purpose Send an Email with or without an attachment without using Outlook or other MAPI client ' Uses Late Binding - Does not need a reference to the Microsoft CDO For Windows library ' But the system CdoSys registered. CDOSys comes standard on Windows 2K and higher ' This code will likely fail on a Win 98 box Const cdoSendUsingPort = 2 Const cdoBasic = 1 Dim objCDOConfig As Object, objCDOMessage As Object Dim strSch As String strSch = "http://Schemas.microsoft.com/cdo/configuration/" Set objCDOConfig = CreateObject("CDO.Configuration") With objCDOConfig.Fields .Item(strSch & "sendusing") = cdoSendUsingPort .Item(strSch & "smtpserver") = "SomeSecureMailServer.SomeDomain.COM" 'Use only when SMTP server requires Authentication - Otherwise Rem out .Item(strSch & "SMTPAuthenticate") = cdoBasic .Item(strSch & "SendUserName") = " .Item(strSch & "SendPassword") = "YourPassword" .Update End With Set objCDOMessage = CreateObject("CDO.Message") With objCDOMessage Set .Configuration = objCDOConfig .From = "Your Nice Name" .Sender = " .To = " .Subject = "Sample CDO Message" '.TextBody = "This is a test for CDO.message" .HTMLBody = "This is a test for CDO.message. This is not Bold But BThis is!/B" '.AddAttachment "c:\Inv83595.pdf" '.MDNRequested = True .Send End With Set objCDOMessage = Nothing Set objCDOConfig = Nothing End Sub I have found that this code to be reliable in my customers environment. Since it uses late binding there are no references to worry about, BUT you need to add error handler for cases where CDO is not available (Win 98), and when the mail server is not available, or authentication fails, or ... Well you get the idea. Ron W "Brad Pears" wrote in message ... I have some sample code on connecting to a mail server using the winsock control to send an email automatically from an Access 2000 project... However, I am not getting a connect request back from the mail server at all...There must be a missing step somewhere... Does someone have some sample code they could send my way that will allow the client computer to connect to an SMTP server over port 25 and send an email? The code I have seems to work but the .Connect request to the email server just sits there and never comes back. It seems as a connection is never established. Here is the sample code.... (Form declaration code) Option Compare Database Dim winsock1 As Winsock (command button code) Private Sub cmdSendMail_Click() Call SMTPSend("mydomain.com", "192.168.2.15", "bradp", "friggin", "This is the Subject", "This is the body") End Sub ' Routine to send email Sub SMTPSend(strMyDomain As String, _ strEmailServer As String, _ strEmailAddressWithoutDomain As String, _ strWhoToSayThisIsFrom As String, _ strSubject As String, _ strMessageBody As String) Set winsock1 = Me!axWinsockServer.Object winsock1.Protocol = sckTCPProtocol winsock1.RemoteHost = strEmailServer winsock1.RemotePort = 25 winsock1.Connect ' Wait for connection WaitForIt Select Case Left$(strWSin, 3) Case "220" ' connected ok, send HELLO winsock1.SendData "HELO " & _ strMyDomain & _ vbCrLf WaitForIt winsock1.SendData "MAIL FROM: " & _ strWhoToSayThisIsFrom & _ vbCrLf WaitForIt winsock1.SendData "RCPT TO: " & _ strWhoToSayThisIsFrom & _ vbCrLf WaitForIt winsock1.SendData "DATA" & vbCrLf & _ "DATE:" & _ Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _ "FROM: " & _ strWhoToSayThisIsFrom & vbCrLf & _ "TO:" & _ Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _ "DATE:" & _ Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _ "SUBJECT: " & _ strSubject & _ vbCrLf & _ strMessageBody & _ vbCrLf & _ "." & vbCrLf ' note: . & vbcrlf terminates the "send" WaitForIt ' parse and validate the return from the sever End Select ' tell the server you're done: winsock1.SendData "QUIT" & vbCrLf ' and that's it! winsock1.Close End Sub Private Sub WaitForIt() WaitingforData = True While WaitingforData = True DoEvents Wend End Sub ' This should run when a connection has been established - but it never does.... Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim Temp As String Temp = String(bytesTotal, " ") winsock1.GetData Temp, vbString Do If Right$(Temp, 1) = vbLf Then Temp = Left$(Temp, Len(Temp) - 1) End If Loop While Right$(Temp, 1) = vbLf strWSin = Temp WaitingforData = False End Sub Any help with this would be greatly appreciated!!! Thanks, Brad |
#22
|
|||
|
|||
Try this
Dim email As New System.Web.Mail.MailMessage() email.To = "RecipientAddress" email.From = "SenderAddress" email.Body = "MessageText" email.Subject = "SubjectText" email.BodyFormat = Web.Mail.MailFormat.Text System.Web.Mail.SmtpMail.SmtpServer = "SmtpServerName" System.Web.Mail.SmtpMail.Send(email) -- Please reply to NG only. This email is not monitored. Alex. "Mangi" wrote in message ... Hi, I would like to do the same thing using VB .Net. Is there an alternative to using winsock in .Net? Maybe a simpler way of creating a VB .Net mail application that would do the same thing without the winsock DataArrival. Thanks, Mangi. "Ron Weiner" wrote: Brad If your clients are Win2K or later you might want to consider sending Via Microsoft CDO. Here is some sample code to get you started. Public Sub testCDO() ' Purpose Send an Email with or without an attachment without using Outlook or other MAPI client ' Uses Late Binding - Does not need a reference to the Microsoft CDO For Windows library ' But the system CdoSys registered. CDOSys comes standard on Windows 2K and higher ' This code will likely fail on a Win 98 box Const cdoSendUsingPort = 2 Const cdoBasic = 1 Dim objCDOConfig As Object, objCDOMessage As Object Dim strSch As String strSch = "http://Schemas.microsoft.com/cdo/configuration/" Set objCDOConfig = CreateObject("CDO.Configuration") With objCDOConfig.Fields .Item(strSch & "sendusing") = cdoSendUsingPort .Item(strSch & "smtpserver") = "SomeSecureMailServer.SomeDomain.COM" 'Use only when SMTP server requires Authentication - Otherwise Rem out .Item(strSch & "SMTPAuthenticate") = cdoBasic .Item(strSch & "SendUserName") = " .Item(strSch & "SendPassword") = "YourPassword" .Update End With Set objCDOMessage = CreateObject("CDO.Message") With objCDOMessage Set .Configuration = objCDOConfig .From = "Your Nice Name" .Sender = " .To = " .Subject = "Sample CDO Message" '.TextBody = "This is a test for CDO.message" .HTMLBody = "This is a test for CDO.message. This is not Bold But BThis is!/B" '.AddAttachment "c:\Inv83595.pdf" '.MDNRequested = True .Send End With Set objCDOMessage = Nothing Set objCDOConfig = Nothing End Sub I have found that this code to be reliable in my customers environment. Since it uses late binding there are no references to worry about, BUT you need to add error handler for cases where CDO is not available (Win 98), and when the mail server is not available, or authentication fails, or ... Well you get the idea. Ron W "Brad Pears" wrote in message ... I have some sample code on connecting to a mail server using the winsock control to send an email automatically from an Access 2000 project... However, I am not getting a connect request back from the mail server at all...There must be a missing step somewhere... Does someone have some sample code they could send my way that will allow the client computer to connect to an SMTP server over port 25 and send an email? The code I have seems to work but the .Connect request to the email server just sits there and never comes back. It seems as a connection is never established. Here is the sample code.... (Form declaration code) Option Compare Database Dim winsock1 As Winsock (command button code) Private Sub cmdSendMail_Click() Call SMTPSend("mydomain.com", "192.168.2.15", "bradp", "friggin", "This is the Subject", "This is the body") End Sub ' Routine to send email Sub SMTPSend(strMyDomain As String, _ strEmailServer As String, _ strEmailAddressWithoutDomain As String, _ strWhoToSayThisIsFrom As String, _ strSubject As String, _ strMessageBody As String) Set winsock1 = Me!axWinsockServer.Object winsock1.Protocol = sckTCPProtocol winsock1.RemoteHost = strEmailServer winsock1.RemotePort = 25 winsock1.Connect ' Wait for connection WaitForIt Select Case Left$(strWSin, 3) Case "220" ' connected ok, send HELLO winsock1.SendData "HELO " & _ strMyDomain & _ vbCrLf WaitForIt winsock1.SendData "MAIL FROM: " & _ strWhoToSayThisIsFrom & _ vbCrLf WaitForIt winsock1.SendData "RCPT TO: " & _ strWhoToSayThisIsFrom & _ vbCrLf WaitForIt winsock1.SendData "DATA" & vbCrLf & _ "DATE:" & _ Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _ "FROM: " & _ strWhoToSayThisIsFrom & vbCrLf & _ "TO:" & _ Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _ "DATE:" & _ Format$(Now(), "mm/dd/yyyy hh:mm:ss") & _ "SUBJECT: " & _ strSubject & _ vbCrLf & _ strMessageBody & _ vbCrLf & _ "." & vbCrLf ' note: . & vbcrlf terminates the "send" WaitForIt ' parse and validate the return from the sever End Select ' tell the server you're done: winsock1.SendData "QUIT" & vbCrLf ' and that's it! winsock1.Close End Sub Private Sub WaitForIt() WaitingforData = True While WaitingforData = True DoEvents Wend End Sub ' This should run when a connection has been established - but it never does.... Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim Temp As String Temp = String(bytesTotal, " ") winsock1.GetData Temp, vbString Do If Right$(Temp, 1) = vbLf Then Temp = Left$(Temp, Len(Temp) - 1) End If Loop While Right$(Temp, 1) = vbLf strWSin = Temp WaitingforData = False End Sub Any help with this would be greatly appreciated!!! Thanks, Brad |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
using the WInsock control.... | Brad Pears | Using Forms | 0 | November 10th, 2004 03:04 PM |
How can I move the focus to a control on a subform? | Brandon | General Discussion | 7 | July 17th, 2004 01:39 AM |
Access Calendar | lost | General Discussion | 2 | July 7th, 2004 04:58 AM |
How to assign value to a report control? | Peter | General Discussion | 3 | June 29th, 2004 11:17 AM |
Inserting a User Control in PowerPoint | Aaron | Powerpoint | 0 | June 22nd, 2004 11:52 PM |