473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

authentication problems sending mail (unable to relay)

Hi all

i need some help. i try to send mail with the following code.

Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim mailMsg As New MailMessage
mailMsg.From = re*******@netradox.com
mailMsg.To = in**@netradox.com
mailMsg.Subject = "Testmail vom Webforum"
mailMsg.Body = "some body text"
SmtpMail.SmtpServer = "localhost"
SmtpMail.SmtpServer()
Try
SmtpMail.Send(mailMsg)
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Module

it works fine as long as i use a user which is located in ADS and the target address is on the same server.

if i try to send mail with the same account in outlook it works fine as long as i set the prperty "my server requires authentication" if i do not set this flag the email is not sent out with the message "unable to relay".

now my question is it possible to set this property within the code somehow or how to solve this?

thank you in advance

Rene
Nov 20 '05 #1
2 1488
Add a reference to system.web and try this code out.

Regards - OHM#

Option Explicit On

Option Strict On

Option Compare Binary

Imports System

Imports System.Text

Imports System.Web.Mail

Imports System.Windows.Forms

Public Class MainForm

Inherits System.Windows.Forms.Form

#Region " Vom Windows Form Designer generierter Code "

Public Sub New()

MyBase.New()

InitializeComponent()

' Eigener Initialisierungscode.

Me.txtFrom.Text = "fr**@anonymous.com"

Me.txtTo.Text = "to@anonymous.com"

Me.txtSubject.Text = "Enter title here..."

Me.txtBody.Text = "Write your message here..."

Me.cboPriority.SelectedIndex = 1

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

Private components As System.ComponentModel.IContainer

Friend WithEvents btnSend As System.Windows.Forms.Button

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents Label3 As System.Windows.Forms.Label

Friend WithEvents Label4 As System.Windows.Forms.Label

Friend WithEvents txtFrom As System.Windows.Forms.TextBox

Friend WithEvents txtTo As System.Windows.Forms.TextBox

Friend WithEvents txtCC As System.Windows.Forms.TextBox

Friend WithEvents txtBCC As System.Windows.Forms.TextBox

Friend WithEvents Label5 As System.Windows.Forms.Label

Friend WithEvents txtSubject As System.Windows.Forms.TextBox

Friend WithEvents txtBody As System.Windows.Forms.TextBox

Friend WithEvents lstAttachments As System.Windows.Forms.ListBox

Friend WithEvents Label6 As System.Windows.Forms.Label

Friend WithEvents cboPriority As System.Windows.Forms.ComboBox

Friend WithEvents btnRemoveAttachment As System.Windows.Forms.Button

Friend WithEvents btnAddAttachment As System.Windows.Forms.Button

Friend WithEvents Label7 As System.Windows.Forms.Label

Friend WithEvents Label8 As System.Windows.Forms.Label

<System.Diagnostics.DebuggerStepThrough()> _

Private Sub InitializeComponent()

Me.btnSend = New System.Windows.Forms.Button()

Me.Label1 = New System.Windows.Forms.Label()

Me.txtFrom = New System.Windows.Forms.TextBox()

Me.Label2 = New System.Windows.Forms.Label()

Me.txtTo = New System.Windows.Forms.TextBox()

Me.Label3 = New System.Windows.Forms.Label()

Me.txtCC = New System.Windows.Forms.TextBox()

Me.Label4 = New System.Windows.Forms.Label()

Me.txtBCC = New System.Windows.Forms.TextBox()

Me.Label5 = New System.Windows.Forms.Label()

Me.txtSubject = New System.Windows.Forms.TextBox()

Me.txtBody = New System.Windows.Forms.TextBox()

Me.lstAttachments = New System.Windows.Forms.ListBox()

Me.Label6 = New System.Windows.Forms.Label()

Me.cboPriority = New System.Windows.Forms.ComboBox()

Me.btnRemoveAttachment = New System.Windows.Forms.Button()

Me.btnAddAttachment = New System.Windows.Forms.Button()

Me.Label7 = New System.Windows.Forms.Label()

Me.Label8 = New System.Windows.Forms.Label()

Me.SuspendLayout()

'

'btnSend

'

Me.btnSend.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.btnSend.Location = New System.Drawing.Point(187, 320)

Me.btnSend.Name = "btnSend"

Me.btnSend.TabIndex = 18

Me.btnSend.Text = "&Send"

'

'Label1

'

Me.Label1.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label1.Location = New System.Drawing.Point(16, 18)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(48, 16)

Me.Label1.TabIndex = 0

Me.Label1.Text = "&From:"

'

'txtFrom

'

Me.txtFrom.Location = New System.Drawing.Point(64, 16)

Me.txtFrom.Name = "txtFrom"

Me.txtFrom.Size = New System.Drawing.Size(192, 20)

Me.txtFrom.TabIndex = 1

Me.txtFrom.Text = ""

'

'Label2

'

Me.Label2.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label2.Location = New System.Drawing.Point(16, 42)

Me.Label2.Name = "Label2"

Me.Label2.Size = New System.Drawing.Size(48, 16)

Me.Label2.TabIndex = 2

Me.Label2.Text = "&To:"

'

'txtTo

'

Me.txtTo.Location = New System.Drawing.Point(64, 40)

Me.txtTo.Name = "txtTo"

Me.txtTo.Size = New System.Drawing.Size(192, 20)

Me.txtTo.TabIndex = 3

Me.txtTo.Text = ""

'

'Label3

'

Me.Label3.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label3.Location = New System.Drawing.Point(16, 66)

Me.Label3.Name = "Label3"

Me.Label3.Size = New System.Drawing.Size(48, 16)

Me.Label3.TabIndex = 4

Me.Label3.Text = "&CC:"

'

'txtCC

'

Me.txtCC.Location = New System.Drawing.Point(64, 64)

Me.txtCC.Name = "txtCC"

Me.txtCC.Size = New System.Drawing.Size(192, 20)

Me.txtCC.TabIndex = 5

Me.txtCC.Text = ""

'

'Label4

'

Me.Label4.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label4.Location = New System.Drawing.Point(16, 90)

Me.Label4.Name = "Label4"

Me.Label4.Size = New System.Drawing.Size(48, 16)

Me.Label4.TabIndex = 6

Me.Label4.Text = "&BCC:"

'

'txtBCC

'

Me.txtBCC.Location = New System.Drawing.Point(64, 88)

Me.txtBCC.Name = "txtBCC"

Me.txtBCC.Size = New System.Drawing.Size(192, 20)

Me.txtBCC.TabIndex = 7

Me.txtBCC.Text = ""

'

'Label5

'

Me.Label5.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label5.Location = New System.Drawing.Point(16, 114)

Me.Label5.Name = "Label5"

Me.Label5.Size = New System.Drawing.Size(48, 16)

Me.Label5.TabIndex = 8

Me.Label5.Text = "S&ubject:"

'

'txtSubject

'

Me.txtSubject.Location = New System.Drawing.Point(64, 112)

Me.txtSubject.Name = "txtSubject"

Me.txtSubject.Size = New System.Drawing.Size(192, 20)

Me.txtSubject.TabIndex = 9

Me.txtSubject.Text = ""

'

'txtBody

'

Me.txtBody.Location = New System.Drawing.Point(16, 168)

Me.txtBody.Multiline = True

Me.txtBody.Name = "txtBody"

Me.txtBody.ScrollBars = System.Windows.Forms.ScrollBars.Both

Me.txtBody.Size = New System.Drawing.Size(416, 144)

Me.txtBody.TabIndex = 13

Me.txtBody.Text = ""

'

'lstAttachments

'

Me.lstAttachments.Location = New System.Drawing.Point(264, 32)

Me.lstAttachments.Name = "lstAttachments"

Me.lstAttachments.Size = New System.Drawing.Size(168, 95)

Me.lstAttachments.TabIndex = 15

'

'Label6

'

Me.Label6.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label6.Location = New System.Drawing.Point(264, 16)

Me.Label6.Name = "Label6"

Me.Label6.Size = New System.Drawing.Size(64, 16)

Me.Label6.TabIndex = 14

Me.Label6.Text = "&Attachments:"

'

'cboPriority

'

Me.cboPriority.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList

Me.cboPriority.Items.AddRange(New Object() {"Low", "Normal", "High"})

Me.cboPriority.Location = New System.Drawing.Point(168, 136)

Me.cboPriority.Name = "cboPriority"

Me.cboPriority.Size = New System.Drawing.Size(88, 21)

Me.cboPriority.TabIndex = 11

'

'btnRemoveAttachment

'

Me.btnRemoveAttachment.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.btnRemoveAttachment.Location = New System.Drawing.Point(352, 134)

Me.btnRemoveAttachment.Name = "btnRemoveAttachment"

Me.btnRemoveAttachment.Size = New System.Drawing.Size(56, 24)

Me.btnRemoveAttachment.TabIndex = 17

Me.btnRemoveAttachment.Text = "&Remove"

'

'btnAddAttachment

'

Me.btnAddAttachment.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.btnAddAttachment.Location = New System.Drawing.Point(288, 134)

Me.btnAddAttachment.Name = "btnAddAttachment"

Me.btnAddAttachment.Size = New System.Drawing.Size(56, 24)

Me.btnAddAttachment.TabIndex = 16

Me.btnAddAttachment.Text = "A&dd..."

'

'Label7

'

Me.Label7.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label7.Location = New System.Drawing.Point(120, 138)

Me.Label7.Name = "Label7"

Me.Label7.Size = New System.Drawing.Size(48, 16)

Me.Label7.TabIndex = 10

Me.Label7.Text = "&Priotity:"

'

'Label8

'

Me.Label8.FlatStyle = System.Windows.Forms.FlatStyle.System

Me.Label8.Location = New System.Drawing.Point(16, 152)

Me.Label8.Name = "Label8"

Me.Label8.Size = New System.Drawing.Size(48, 16)

Me.Label8.TabIndex = 12

Me.Label8.Text = "&Message:"

'

'MainForm

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(448, 360)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label8,
Me.Label7, Me.btnAddAttachment, Me.btnRemoveAttachment, Me.cboPriority,
Me.Label6, Me.lstAttachments, Me.txtBody, Me.Label5, Me.txtSubject,
Me.Label4, Me.txtBCC, Me.Label3, Me.txtCC, Me.Label2, Me.txtTo, Me.Label1,
Me.txtFrom, Me.btnSend})

Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle

Me.MaximizeBox = False

Me.Name = "MainForm"

Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n

Me.Text = "SendMail"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSend.Click

Dim mailmsg As New MailMessage()

With mailmsg

..From = Me.txtFrom.Text.Trim()

..To = Me.txtTo.Text.Trim()

..Cc = Me.txtCC.Text.Trim()

..Bcc = Me.txtBCC.Text.Trim()

..Subject = Me.txtSubject.Text.Trim()

..Body = Me.txtBody.Text.Trim()

Select Case Me.cboPriority.SelectedIndex

Case 0

..Priority = MailPriority.Low

Case 1

..Priority = MailPriority.Normal

Case 2

..Priority = MailPriority.High

End Select

Dim s As String

For Each s In Me.lstAttachments.Items

..Attachments.Add(New MailAttachment(s))

Next s

End With

Try

SmtpMail.Send(mailmsg)

MessageBox.Show("Your mail has been successfully sent!")

Catch ex As Exception

MessageBox.Show("The following problem occurred when attempting to send your
mail: " & ex.Message)

End Try

End Sub

Private Sub btnAddAttachment_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAddAttachment.Click

Dim ofdlg As New OpenFileDialog()

ofdlg.CheckFileExists = True

ofdlg.CheckPathExists = True

If ofdlg.ShowDialog(Me) = DialogResult.OK Then

Me.lstAttachments.Items.Add(ofdlg.FileName)

End If

End Sub

Private Sub btnRemoveAttachment_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnRemoveAttachment.Click

If Me.lstAttachments.SelectedIndex >= 0 Then

Me.lstAttachments.Items.Remove(Me.lstAttachments.S electedItem)

End If

End Sub

End Class

Rene wrote:
Hi all

i need some help. i try to send mail with the following code.

Private Sub LinkButton1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles LinkButton1.Click Dim
mailMsg As New MailMessage mailMsg.From = re*******@netradox.com
mailMsg.To = in**@netradox.com
mailMsg.Subject = "Testmail vom Webforum"
mailMsg.Body = "some body text"
SmtpMail.SmtpServer = "localhost"
SmtpMail.SmtpServer()
Try
SmtpMail.Send(mailMsg)
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
End Module

it works fine as long as i use a user which is located in ADS and the
target address is on the same server.

if i try to send mail with the same account in outlook it works fine
as long as i set the prperty "my server requires authentication" if i
do not set this flag the email is not sent out with the message
"unable to relay".

now my question is it possible to set this property within the code
somehow or how to solve this?

thank you in advance

Rene


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #2
I will tra your code also. thank you for help

i've found a solution which work fine for me.
Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim mailMsg As New MailMessage

mailMsg.From = "in**@netradox.com"
mailMsg.To = "re*******@thf.com"
mailMsg.Subject = "Testmail from Info"
mailMsg.Body = "some body Text"
SmtpMail.SmtpServer = System.Configuration.ConfigurationSettings.AppSett ings.Get("localhost")

Try
SmtpMail.Send(mailMsg)
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub

Regards, Rene
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Owen | last post by:
I am sending email using CDO but it only seems to work when the "To" address is within the same domain as mine. When I send to an outside domain (eg. yahoo.com) the mail simply does not reach...
1
by: Venkat | last post by:
I have win-2003. body ="Test body"; MailMessage mail = new MailMessage(); mail.From = "Test_From"; mail.To = "name@domain-name.com"; mail.Subject = "Mail-Html format"; mail.Body = body;...
1
by: Cantekin Guneser | last post by:
i try to send mail in my wep application, i use code below private void B_Ok_Click(object sender, System.EventArgs e) { MailMessage msg = new MailMessage(); msg.To =...
0
by: Rupreet Singh | last post by:
Hi! Is the relaying properly configured. Try opening the relaying on your server. I got the problem and after opening the relaying on the local server, it got solved! Try it! Regards Rupreet ...
3
by: Chris Thunell | last post by:
I am using the following code to send email out in a vb.net web program through an exchange 2003 server. My web server is on a separate server. When i try to send email inside the office, it works...
2
by: Arne Beruldsen | last post by:
I have an online app via webforms. When the user completes the final step...I would like the app to automatically send an email to a specific individual. I'm using the following code: Imports...
3
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is...
5
by: Mark A. Sam | last post by:
Hello, I am sending two emails from the same procedure, one to myself (while testing) and another (a comfirmation) to the user on the website. I was having difficulty finding a relay server to...
3
by: armando perez | last post by:
Hi, this is my first time here, but I was looking for something that may help me, and still, I haven't found something to use. I'm using a website made in .NET with C#, when I'm running my site...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.