|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am tring to send emails in VB.Net application using SMTPMail class.
But my messages only show up in queue folder on my computer and never show in the actual input box of the recipient.I use aol as net provider and I did set my SMTPmail.servername to localhost.What am I doing wrong? |
|
#2
|
|||
|
|||
|
VB.NET e-mail messages
I had a great deal of trouble getting Visual Basic .NET to send e-mail messages. Here is the approach that I stumbled onto. Note that it uses CDO for NTS, not Windows 2000, and dependencies include adodb, CDONTS, Excel, and Office at least.
Sub Main() 'allocate memory for the objects Dim cn As ADODB.Connection 'connection to database Dim rsTechs As ADODB.Recordset 'list of technicians etc. Dim GoForIt As Boolean 'shows whether to process Dim testString As String Dim body As String Dim rsOrders As ADODB.Recordset Dim cmdExec As ADODB.Command Dim wks As Excel._Worksheet Dim wkb As Excel._Workbook Dim wka As Excel.Application Dim column, row, records, fldCount, iCol As Integer Dim path As String 'Instantiate the ADODB connection and recordset objects cn = New ADODB.Connection rsTechs = New ADODB.Recordset cmdExec = New ADODB.Command 'Configure and open the connection cn.Open("Provider=SQLOLEDB.1;Password= . . . ;Persist Security Info=True;" & _ "User ID= . . . ;Initial Catalog=. . . ;Data Source=. . . ") 'configure the command object cmdExec.ActiveConnection = cn 'lots of application specific processing here 'Instantiate the email message object Dim NewMessage As CDONTS.NewMail NewMessage = New CDONTS.NewMail 'Set NewMessage's parameters that are result independent NewMessage.To = rsTechs("emailaddress").Value NewMessage.From = ". . . " NewMessage.Subject = "Open Work Orders" NewMessage.MailFormat = CDONTS.CdoMailFormats.CdoMailFormatMime NewMessage.BodyFormat = CDONTS.CdoBodyFormats.CdoBodyFormatHTML 'Set NewMessage's result-specific parameters If records = 0 Then NewMessage.Body = "You have no open work orders. To change your reporting preferences, please reply to this e-mail message and indicate on which weekdays, if any, you would like to receive this report. Thanks. Art." Else body = "You have " If records = 1 Then body = body & "one open work order." Else body = body & records & " open work orders." End If body = body & " To change your reporting preferences, please reply to this e-mail message and indicate on which weekdays, if any, you would like to receive this report. Thanks. Art." & vbCrLf & vbCrLf NewMessage.Body = body 'attach the spreadsheet to the e-mail message NewMessage.AttachFile(path & "\DailyReport.xls") End If 'send the e-mail message NewMessage.Send() End If NewMessage = Nothing rsOrders = Nothing |
|
#3
|
|||
|
|||
|
Cant send email in vb.net
I found that if you set the smtp.server as "" It seems to work
Here is a class I used Code:
Imports System.Web.Mail
Public Class SendAdminMail
Public Function sendmail(ByVal PID As String, ByVal Name As String, ByVal SQA As String) As String
Dim response As String
Dim objMailMessage As MailMessage
Dim objMailAttachment As MailAttachment
'Change this to the Smtp server address of website
Try
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("smtpServer")
' Create the Mail Message
objMailMessage = New MailMessage()
objMailMessage.From = "Admin@SQAIntranet.pace.co.uk"
objMailMessage.To = ConfigurationSettings.AppSettings("AdminEmail")
objMailMessage.Subject = "SQA Website email"
objMailMessage.Body = PID & ", " & Name & ", " & SQA
objMailMessage.BodyFormat = MailFormat.Text
' Send the Mail Message
SmtpMail.Send(objMailMessage)
Catch
response = "Send Mail Failed"
Return response
End Try
Return response
End Function
End Class
You just need an appsettings tag in your web.config file with the STMP server ip address (or "" if local) I also found that the queue sits there doing nothing on localhost if there is any kind of error in one of the items queued. Scott. |
|
#4
|
|||
|
|||
|
Cant send email in vb.net
Another approach would be to set the smtp.servername to the ip address of your AOL email server......
Scott. |
|
#5
|
|||
|
|||
|
I found the SMTP class in .Net and CDONTS to be vey annoying and limited. My solution and recommendation is to look up the RFC for SMTP server transmission, and do it that way. I'm currrently working on such a class, but won't be done untill later this week. But, I've found that CDONTS can't talk to anything other than Exchange or basic SMTP very well, and the authentication scheme is very annoying, even though it's a simple Base4 stream.
Anyway, that's my 2cents on it. Tibby |
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Can't send effective email in VB.NET |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|