473,703 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Cli ck(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles LinkButton1.Cli ck
Dim mailMsg As New MailMessage
mailMsg.From = re*******@netra dox.com
mailMsg.To = in**@netradox.c om
mailMsg.Subject = "Testmail vom Webforum"
mailMsg.Body = "some body text"
SmtpMail.SmtpSe rver = "localhost"
SmtpMail.SmtpSe rver()
Try
SmtpMail.Send(m ailMsg)
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 1503
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()

InitializeCompo nent()

' Eigener Initialisierung scode.

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

Me.txtTo.Text = "to@anonymous.c om"

Me.txtSubject.T ext = "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.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

Private components As System.Componen tModel.IContain er

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 btnRemoveAttach ment As System.Windows. Forms.Button

Friend WithEvents btnAddAttachmen t As System.Windows. Forms.Button

Friend WithEvents Label7 As System.Windows. Forms.Label

Friend WithEvents Label8 As System.Windows. Forms.Label

<System.Diagnos tics.DebuggerSt epThrough()> _

Private Sub InitializeCompo nent()

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.lstAttachmen ts = New System.Windows. Forms.ListBox()

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

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

Me.btnRemoveAtt achment = New System.Windows. Forms.Button()

Me.btnAddAttach ment = New System.Windows. Forms.Button()

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

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

Me.SuspendLayou t()

'

'btnSend

'

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

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

Me.btnSend.Name = "btnSend"

Me.btnSend.TabI ndex = 18

Me.btnSend.Text = "&Send"

'

'Label1

'

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

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

Me.Label1.Name = "Label1"

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

Me.Label1.TabIn dex = 0

Me.Label1.Text = "&From:"

'

'txtFrom

'

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

Me.txtFrom.Name = "txtFrom"

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

Me.txtFrom.TabI ndex = 1

Me.txtFrom.Text = ""

'

'Label2

'

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

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

Me.Label2.Name = "Label2"

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

Me.Label2.TabIn dex = 2

Me.Label2.Text = "&To:"

'

'txtTo

'

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

Me.txtTo.Name = "txtTo"

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

Me.txtTo.TabInd ex = 3

Me.txtTo.Text = ""

'

'Label3

'

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

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

Me.Label3.Name = "Label3"

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

Me.Label3.TabIn dex = 4

Me.Label3.Text = "&CC:"

'

'txtCC

'

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

Me.txtCC.Name = "txtCC"

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

Me.txtCC.TabInd ex = 5

Me.txtCC.Text = ""

'

'Label4

'

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

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

Me.Label4.Name = "Label4"

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

Me.Label4.TabIn dex = 6

Me.Label4.Text = "&BCC:"

'

'txtBCC

'

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

Me.txtBCC.Name = "txtBCC"

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

Me.txtBCC.TabIn dex = 7

Me.txtBCC.Text = ""

'

'Label5

'

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

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

Me.Label5.Name = "Label5"

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

Me.Label5.TabIn dex = 8

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

'

'txtSubject

'

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

Me.txtSubject.N ame = "txtSubject "

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

Me.txtSubject.T abIndex = 9

Me.txtSubject.T ext = ""

'

'txtBody

'

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

Me.txtBody.Mult iline = True

Me.txtBody.Name = "txtBody"

Me.txtBody.Scro llBars = System.Windows. Forms.ScrollBar s.Both

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

Me.txtBody.TabI ndex = 13

Me.txtBody.Text = ""

'

'lstAttachments

'

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

Me.lstAttachmen ts.Name = "lstAttachments "

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

Me.lstAttachmen ts.TabIndex = 15

'

'Label6

'

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

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

Me.Label6.Name = "Label6"

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

Me.Label6.TabIn dex = 14

Me.Label6.Text = "&Attachmen ts:"

'

'cboPriority

'

Me.cboPriority. DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st

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

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

Me.cboPriority. Name = "cboPriorit y"

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

Me.cboPriority. TabIndex = 11

'

'btnRemoveAttac hment

'

Me.btnRemoveAtt achment.FlatSty le = System.Windows. Forms.FlatStyle .System

Me.btnRemoveAtt achment.Locatio n = New System.Drawing. Point(352, 134)

Me.btnRemoveAtt achment.Name = "btnRemoveAttac hment"

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

Me.btnRemoveAtt achment.TabInde x = 17

Me.btnRemoveAtt achment.Text = "&Remove"

'

'btnAddAttachme nt

'

Me.btnAddAttach ment.FlatStyle = System.Windows. Forms.FlatStyle .System

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

Me.btnAddAttach ment.Name = "btnAddAttachme nt"

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

Me.btnAddAttach ment.TabIndex = 16

Me.btnAddAttach ment.Text = "A&dd..."

'

'Label7

'

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

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

Me.Label7.Name = "Label7"

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

Me.Label7.TabIn dex = 10

Me.Label7.Text = "&Priotity: "

'

'Label8

'

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

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

Me.Label8.Name = "Label8"

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

Me.Label8.TabIn dex = 12

Me.Label8.Text = "&Message:"

'

'MainForm

'

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

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

Me.Controls.Add Range(New System.Windows. Forms.Control() {Me.Label8,
Me.Label7, Me.btnAddAttach ment, Me.btnRemoveAtt achment, Me.cboPriority,
Me.Label6, Me.lstAttachmen ts, 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.FormBorderSt yle = System.Windows. Forms.FormBorde rStyle.FixedSin gle

Me.MaximizeBox = False

Me.Name = "MainForm"

Me.StartPositio n = System.Windows. Forms.FormStart Position.Center Screen

Me.Text = "SendMail"

Me.ResumeLayout (False)

End Sub

#End Region

Private Sub btnSend_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnSend.Click

Dim mailmsg As New MailMessage()

With mailmsg

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

..To = Me.txtTo.Text.T rim()

..Cc = Me.txtCC.Text.T rim()

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

..Subject = Me.txtSubject.T ext.Trim()

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

Select Case Me.cboPriority. SelectedIndex

Case 0

..Priority = MailPriority.Lo w

Case 1

..Priority = MailPriority.No rmal

Case 2

..Priority = MailPriority.Hi gh

End Select

Dim s As String

For Each s In Me.lstAttachmen ts.Items

..Attachments.A dd(New MailAttachment( s))

Next s

End With

Try

SmtpMail.Send(m ailmsg)

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 btnAddAttachmen t_Click(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnAddAttachmen t.Click

Dim ofdlg As New OpenFileDialog( )

ofdlg.CheckFile Exists = True

ofdlg.CheckPath Exists = True

If ofdlg.ShowDialo g(Me) = DialogResult.OK Then

Me.lstAttachmen ts.Items.Add(of dlg.FileName)

End If

End Sub

Private Sub btnRemoveAttach ment_Click(ByVa l sender As System.Object, ByVal e
As System.EventArg s) Handles btnRemoveAttach ment.Click

If Me.lstAttachmen ts.SelectedInde x >= 0 Then

Me.lstAttachmen ts.Items.Remove (Me.lstAttachme nts.SelectedIte m)

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_Cli ck(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles LinkButton1.Cli ck Dim
mailMsg As New MailMessage mailMsg.From = re*******@netra dox.com
mailMsg.To = in**@netradox.c om
mailMsg.Subject = "Testmail vom Webforum"
mailMsg.Body = "some body text"
SmtpMail.SmtpSe rver = "localhost"
SmtpMail.SmtpSe rver()
Try
SmtpMail.Send(m ailMsg)
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**********@BT Internet.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_Cli ck(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles LinkButton1.Cli ck
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.SmtpSe rver = System.Configur ation.Configura tionSettings.Ap pSettings.Get(" localhost")

Try
SmtpMail.Send(m ailMsg)
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
9208
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 the recipient. I have been testing this with my own email address. There is no error reported and everything "appears" to have worked except for the fact the email does not reach the recipient. I had this problem with CDONTS and thought that...
1
1226
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; mail.BodyFormat = MailFormat.Html;
1
1597
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 = "cantekinguneser@hotmail.com";
0
1062
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 >-----Original Message----- >Why do I get the Message: "550 5.7.1 Unable to relay for
3
2429
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 fine... but when i try to send email outside the company i get "unable to relay" error message. Please look at the code, i don't see a way to send username and password credentials to allow the relaying to occur (I don't want unauthenticated...
2
1648
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 System.Web.Mail .... Dim Mail As New MailMessage Mail.To = "beruldsen@hemingwaysoftware.com" Mail.Subject = "Howdy" Mail.From = "beruldsen@cox.com" SmtpMail.SmtpServer = "localhost" SmtpMail.Send(Mail)
3
3614
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 smtpMail.Send("from@here.com", to@there.com, "Message subject", "Message Body") I'm sending it to my own email address on a different server using a dummy
5
4883
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 SMTP though, but was able to do this though one of my personal account, Cabbage.Org. It doesn't make any sense to me why this works and no other account, including localhost and the remote server which hosts the website. Here is a code snippet...
3
4275
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 from my PC, everything seems right, but when I publish the website, and send it to my real website, everything works but the mail sending. I have red some groups and topics, and everywhere I can found: - Use the following syntax: <system.net>
0
8750
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8662
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9244
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7853
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2439
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2058
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.