Solved

Error sending email via SMTP

Posted on 2008-06-12
9
1,844 Views
Last Modified: 2013-11-07
I  am having a hard time sending email from my application with the system.net.mail functions.

I keep getting errors like 'fully qualified name needed' or 'relay access denied'

I CAN seem to send them with third party tools such as a command line email tool
or another tool.  

Now, I DO need to send authentication info, so I have to pass User and Password

Here is the command line that works:
==============================
febootimail.exe -FROM theanswerman@yahoo.com -TO theanswerman2@yahoo.com -MSG "test body" -SUBJ "test subject" -SMTP postbox.MyComp.com -USER "theanserman@MyComp.com" -PASS "MyPass123"

This third party component also works:
=================================
 
Dim Mailman As New Chilkat.MailMan
Dim email As New Chilkat.Email()
Dim bSuccess As Boolean

Mailman.SmtpHost = "postbox.MyComp.com"
Mailman.SmtpUsername = "theanserman@MyComp.com"
Mailman.SmtpPassword = "MyPass123"
Mailman.SmtpLoginDomain = "MyCompDomain"

email.Subject = "test subject"
email.Body = "test body"
email.AddTo("Penni", "theanswerman2@MyComp.com")

bSuccess = Mailman.SendEmail(email)
           
If (bSuccess <> True) Then
       MsgBox(Mailman.LastErrorText)
       Exit Sub
End If


Here is the code that just craps out on the send command.
==============================================
Dim obj As New System.Net.Mail.SmtpClient
Dim Mailmsg As New System.Net.Mail.MailMessage
Dim oAdd As MailAddress

Dim oAddrFrom As New System.Net.Mail.MailAddress("theanswerman@MyComp.com")
Dim oAddrTo As New System.Net.Mail.MailAddress("theanswerman2@MyComp.com")
Dim oMailSender As New System.Net.Mail.SmtpClient("postbox.MyComp.com")
Dim oMessage As New MailMessage(oAddrFrom, oAddrTo)

Mailmsg.Subject = "test subject"
Mailmsg.Body = "test body"
oMailSender.Credentials = New System.Net.NetworkCredential("theanserman@MyComp.com", "MyPass123", "MyCompDomain")

oMailSender.Send(oMessage)    '//THIS LINE FAILS

depending on how i mess with the settings.. I will either get "need fully qualified"
or "relay denied"
0
Comment
Question by:TheAnswerMan
9 Comments
 
LVL 3

Author Comment

by:TheAnswerMan
ID: 21774391
t
0
 
LVL 11

Expert Comment

by:AkisC
ID: 21776764
I have been using the sub below with no problems -but- some people prefer a more .NET way

    Sub SendMail_CDOSYS(ByVal MailBody As String, ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal atchFile As String)
        On Error Resume Next
        MailBody = Replace(MailBody, vbCrLf & "<br>", "<br>")
        MailBody = Replace(MailBody, vbCrLf, "<br>")
        '
        Dim oCdoMail, oCdoConf As Object, sConfURL As String = ""
        oCdoMail = CreateObject("CDO.Message")
        oCdoConf = CreateObject("CDO.Configuration")
        sConfURL = "http://schemas.microsoft.com/cdo/configuration/"
        '
        With oCdoConf
            .Fields.Item(sConfURL & "sendusing") = 2
            .Fields.Item(sConfURL & "smtpserver") = "smtp.yahoo.com"  'change this to your smtp server
            .Fields.Item(sConfURL & "smtpserverport") = 25
            .Fields.item(sConfURL & "sendpassword") = "myPass" 'email account password
            .Fields.item(sConfURL & "sendusername") = "user@yahoo.com" 'your email
            .Fields.Update()
        End With
        '
        Dim iBP
        With oCdoMail
            .From = strFrom
            .To = strTo
            .Subject = strSubject
            .TextBody = MailBody
            .HTMLBody = MailBody
            If Trim(atchFile) <> "" Then
                iBP = oCdoMail.AddAttachment(atchFile)
            End If
            .Configuration = oCdoConf
            .Send()
        End With
        '
        oCdoConf = Nothing
        oCdoMail = Nothing
        On Error GoTo 0
 
    End Sub

Open in new window

0
 
LVL 7

Expert Comment

by:photowhiz
ID: 21780707
SMTP is a rather large protocol, and there are many details in handling it correctly. There are excellent tutorials on handling it through System.Net.Mail at http://www.systemnetmail.com/
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 3

Author Comment

by:TheAnswerMan
ID: 21781908
AkisC

I get the same error.

The server rejected one or more recipient addresses. The server response was: 504 5.5.2 <paydavidc1>: Helo command rejected: need fully-qualified hostname

or

The server rejected one or more recipient addresses. The server response was: 554 5.7.1 <myxlplik@yahoo.com>: Relay access denied
0
 
LVL 11

Expert Comment

by:AkisC
ID: 21784238
"smtpserver") = "smtp.yahoo.com"  you might need to replace this with something else
-also-
myxlplik@yahoo.com might need to be just "myxlplik"

Relay access denied:::need fully-qualified hostname
:::Probablly the errors you get is why yahoo does not allow anything to pass throught their mail server unless it originates from one of yahoo servers

If you have another email (from an ISP or Hosting provider) the code works.
0
 
LVL 3

Author Comment

by:TheAnswerMan
ID: 21784277
My apologies.

I just entered that "smtp.yahoo.com" items to obfuscate the actual domain and company.

The smtpserver entry  is basically postbox.mycompany.com

the myxlplik@yahoo.com is another obfuscation.  the real one is my actual email address at the company.
This infomation i copied from the Control panel Mail settings.  We use Outlook to connect to zimbra, so it shows me the smtp values.

These same values I use on the "third party" controls that somehow do work with the
postbox.mycompany.com and passing in my email and login as the username and password.

I would just think I could use those values when using the system.net.mail objects.

I did make a change to the machine name in windows   So now it has mymachinename.mydomain
rather than what is used to be just my machine name.
I thought this would make it "fully qualified, but I guess not.

My problem is that without passing any other info,  the other email components manage to send the emails.
0
 
LVL 3

Author Comment

by:TheAnswerMan
ID: 22035783
Apparently the issue is with regarding some kind of private variable in the mail object.

it has to do with security on the mail server and sending a fully qualified name.
0
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 22110970
Hi there,

Heres a function I use to send mail via the .net smtp client. This should do what your after

Regards
Steve


Imports System.Net.Mail
 
Public Sub SendEmail(ByVal sender As String, _
    ByVal recipient As String, ByVal subject As String, _
    ByVal body As String, Optional ByVal attachmentString As String = "")
 
        Dim fromAddress As New MailAddress(sender)
        Dim toAddress As New MailAddress(recipient)
        Dim message As New MailMessage(fromAddress, toAddress)
 
        Dim mailSender As SmtpClient
        mailSender = New SmtpClient("smtp.yourserver.com", 25)
        mailSender.Credentials = New NetworkCredential("username", "password")
 
        message.Bcc.Add(fromAddress)
        message.Subject = subject
        message.IsBodyHtml = False
        message.Body = body
 
        If Not attachmentString = "" Then
            Dim msgAttach As New Attachment(attachmentString)
            message.Attachments.Add(msgAttach)
        End If
 
        Try
            mailSender.Send(message)
 
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
 
    End Sub

Open in new window

0
 
LVL 3

Accepted Solution

by:
TheAnswerMan earned 0 total points
ID: 22123667
OK I was able to work it out.

private variable not being set with WSID.    'Jimbo.Mydomain.com'

I found this explanation:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94378&wa=wsignin1.0

There is one suggested workaround:
https://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=94378

Thanks for trying.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question