Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending email to subscribers in a listserv

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
I am trying to add email subsribers to the listserv and I am getting the below error message. can someone help

Code:
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        Dim strEmailAddress As String = txtEmailAddress.Text.Trim.ToString.ToLower
        Dim strName As String = txtName.Text.Trim.ToString
        Dim mailDelivery As New MailMessage


        If RadioButtonList1.SelectedIndex = 0 Then
            mailDelivery.Subject = "Subscribe"
            mailDelivery.Body = "subscribe testlist" & strName & vbCrLf
            Response.Write("Thank you. You should receive a confirmation email about your subscribtion shortly.")
        Else

            mailDelivery.Subject = "Unsubscribe"
            mailDelivery.Body = "unsubscribe testlist " & vbCrLf
            Response.Write("Thank you. You will be removed from the HPDP mailing list")
        End If
        mailDelivery.From = New MailAddress(strEmailAddress)
        mailDelivery.To.Add(New MailAddress("listserv@.xxx.xxxxx.xx.xx"))
        mailDelivery.IsBodyHtml = False

        Dim SmtpMail As New SmtpClient()
        SmtpMail.Send(mailDelivery)
    End Sub
Mailbox unavailable. The server response was: Relaying denied
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: Relaying denied

Source Error:


Line 30:
Line 31: Dim SmtpMail As New SmtpClient()
Line 32: SmtpMail.Send(mailDelivery)
Line 33: End Sub
Line 34:

 
the problem is not the code. at least not directly. you may need to supply a username and password to authenticate the message being sent.

I would also make 2 other changes.
1. pull the email sending code into another method (or another class) This will separate the concerns of actually sending the email and responding to the users request.
2. use a label to inform the user the message was sent, not Response.Write().

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Thank you jason for your reply. I spoke with the server admn and here is what he said to me: Mail sent to will not relay unless the IP address is added to a relay lis.
I will let you know the final out come.
 
I do not think it is a code problem. please let me know if someone has the same kind of problem and how it can be fixed. It looks like configuration issue and I google and tried all the suggestion and so far to no avail. here is the error message: I wonder if it is asking me the IP address for the listserv?


Code:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for listserv@dot.state.mn.us 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for listserv@xxx.sxxx.xx.xxx

Source Error: 


Line 34:         SmtpMail.UseDefaultCredentials = False
Line 35:         SmtpMail.Port = "25"
Line 36:         SmtpMail.Send(mail)
Line 37:         emailConfirmation()
Line 38:     End Sub
 
You don't have a local smtp mail relay setup. I use gmail where I can't set up a mail relay because of corporate policy. If you don't have one you can set one up in 5 minutes for free.


MailMessage message = new MailMessage();


message.Body = "Hello";
message.Subject = "My Email";
message.To.Add("someone@hotmail.com");
message.IsBodyHtml = false; ;

SmtpClient client = new SmtpClient();
client.EnableSsl = true;//for Gmail this should be true.
client.Send(message);

put this in your web.config
<system.net>
<mailSettings>
<smtp from="mygmailAcount@gmail.com" >
<network defaultCredentials="false" host="smtp.gmail.com" port="587" userName="MyUserName" password="MyPassword!" />
</smtp>
</mailSettings>
</system.net>
 
After a few furstration dates. I figured out the problem and want to share with you. I found out a cople things.
1- Our list serve was cas senstive and I had to change to this: SUBSCRIBE AND UNSUBSCRIBE AND
2- for some reason It did not like the VbCrlf in the code. I took care of those two now I am a happy camper. thank you all for provding me your help.


Code:
 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        Dim strEmail As String = txtEmailAddress.Text.Trim.ToString.ToLower
        Dim strName As String = txtName.Text.Trim.ToString
        Dim MailFrom As New MailAddress(strEmail)
        Dim MailTo As New MailAddress("LISTSERV@xxx.xxx.xxx.xxx", "TESTLIST")
        Dim message As New MailMessage(MailFrom, MailTo)
        Dim client As New SmtpClient()

        If RdSubsAndUnSub.SelectedIndex = 0 Then
            message.Subject = "Subscribe"
            message.Body = "SUBSCRIBE TESTLIST " & strName
        Else
            message.Subject = "Unsubscribe"
            message.Body = "UNSUBSCRIBE TESTLIST"
        End If

        message.IsBodyHtml = False
        client.Send(message)
        emailConfirmation()
    End Sub
    Sub emailConfirmation()
        If RdSubsAndUnSub.SelectedIndex = 0 Then
            lblConfirm.Text = "Thank you for subscribing to HPDP mailing list. You should receive a confirmation email shortly."
        Else
            lblConfirm.Text = "Thank you. You will be removed from the HPDP mailing list."
        End If
    End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top