You must Sign In to post a response.
  • Category: ASP.NET

    Error in address "paramter address string cannot be empty"

    Hi when I was running below code it shows parameter address cannot be empty.
    Public Sub sendEmail(ByVal recepient As String, ByVal alertID As String)
    Dim arrSendTo() As String = recepient.Split(",").Distinct.ToArray
    For i = 0 To arrSendTo.Count - 1
    'create the mail message
    Dim mail As New MailMessage()
    'set the addresses
    mail.[To].Add(getEmail(arrSendTo(i)))
    'set the content
    mail.Subject = "DRS New Registration - " & txtTitle.Text
    mail.Body = "<html><body>" & _
    "<p>Dear " & getUserName(arrSendTo(i), "name") & ",</p>" & _
    "<p>You have Registered : " & txtTitle.Text & _
    "<br />CreatedOn: " & lblCreatedOn.Text & _
    "<br />ReferenceNo: " & txtReferenceNo.Text & _
    "<br />Counterparty Name: " & txtCounterParty.Text &
    "<br />Remarks: " & txtRemarks.Text & _
    "</p><p>You may update the Registration Status via this <a href='http://sng-cmsdev-d01:8088/edit.aspx?userID=" & Encrypt(arrSendTo(i)) & "&alertID=" & alertID & "' target='_blank'>link</a> </p>" & _
    "<p>Regards,<br />Administrator</p>" & _
    "</body></html>"
    mail.IsBodyHtml = True
    'set the server
    Dim smtp As New SmtpClient()
    'send the message
    Try
    smtp.Send(mail)
    Catch exc As Exception
    End Try
    Next
    End Sub

    Can anyone help me to fix this error below is the code to get email address from sql

    Public Function getEmail(ByVal userID As String) As String
    Dim emailAddr As String = ""
    Dim conSQL As New SqlConnection(conStrDRS)

    conSQL.Open()

    Dim cmdSQL As SqlCommand = New SqlCommand("SELECT User_Email FROM [dbo].[UserAccess] WHERE User_Login_ID='" & userID & "'")

    cmdSQL.Connection = conSQL
    Dim adptSQL As New SqlClient.SqlDataAdapter(cmdSQL)
    Dim myDataSet As New DataSet()
    adptSQL.Fill(myDataSet)
    With myDataSet.Tables(0)
    For rowNumber As Integer = 0 To .Rows.Count - 1
    With .Rows(rowNumber)
    emailAddr = .Item(0).ToString
    End With
    Next
    End With

    conSQL.Close()
    Return emailAddr
    End Function
    Can anyone help me to fix this issue. And Can anyone help me how to send email based on status .
    The code is vb.net. Thanks!!
  • #764248
    Hi Nagendra,

    1) I think your getEmail() method is returning an empty string, so place a debugger inside getEmail() method and check what valve it retrieves from database.
    2) Where is your "From" email address???
    try to put following before 'set the addresses line
    mail.From = New MailAddress("xyz@gmail.com")
    OR
    mail.From = New MailAddress("YourMailId@gmail.com", "Developers", System.Text.Encoding.UTF8)

    Hope it helps.

    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764249
    Check are you getting the email address data in the following content

    In the following code the array count may be 0

    For i = 0 To arrSendTo.Count - 1
    'create the mail message
    Dim mail As New MailMessage()
    'set the addresses
    mail.[To].Add(getEmail(arrSendTo(i)))

    Are you getting the data in "arrSendTo(i)"


    And also send you "From" address

    By Nathan
    Direction is important than speed

  • #764251
    Hi Sashikanth From address is default I have included in SMTP. How to check whether value is giving in database

  • #764252
    Hi Nathan from address is included in SMTP server the email address should get from database if the above code looks wrong can you please suggest with the correct one

  • #764254
    It looks there is error in TO part of mail, you need to check what email id you have given in TO part, you can try below code snippet
    message.To.Add(New MailAddress(toEmailAddress));

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764256
    Did you checked whether are you getting email address in
    "mail.[To].Add(getEmail(arrSendTo(i)))"


    Handle the error message clearly so that you can easily identify the issue.


    string zEmailToListP = "your Email List";
    List<string> zEmailToListL = new List<string>();
    string[] zToAddressesL = zEmailToListP.Split(new char[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
    foreach (string zToAddressL in zToAddressesL)
    {
    zEmailToListL.Add(zToAddressL);
    }

    using (MailMessage aMailL = new MailMessage())
    {
    if (zEmailToListP != null)
    {
    if (zEmailToListP.Count > 0)
    {
    foreach (string zMailAddressL in zEmailToListP)
    {
    aMailL.To.Add(zMailAddressL);
    }
    }
    else
    {
    return "Minimum one EmailAddress is required to send the mail";
    }
    }
    else
    {
    return "Minimum one EmailAddress is required to send the mail";
    }
    if (!string.IsNullOrEmpty(zSubjectP))
    {
    aMailL.Subject = zSubjectP;
    }
    else
    {
    return = "Subject Should not be empty";
    }
    string zBodyL = "";
    if (zBodyP != null)
    {
    zBodyL = zBodyP;
    }
    aMailL.Body = zBodyL;
    aMailL.IsBodyHtml = true;// Can set to false, if you are sending pure text.
    SmtpClient TheSmtpClientL = new SmtpClient();
    TheSmtpClientL.Host = zSmtpServerHostP;
    if (nPortNumberP != 0)
    {
    TheSmtpClientL.Port = nPortNumberP;
    }
    if (bIsEnableSSLP)
    {
    TheSmtpClientL.EnableSsl = bIsEnableSSLP;
    }
    if (zSmtpServerUidP != "" && zSmtpServerPwdP != "")
    {
    TheSmtpClientL.UseDefaultCredentials = false;
    TheSmtpClientL.Credentials = new System.Net.NetworkCredential(zSmtpServerUidP, zSmtpServerPwdP);
    }
    else
    {
    TheSmtpClientL.UseDefaultCredentials = true;
    }
    TheSmtpClientL.Send(aMailL);
    }

    By Nathan
    Direction is important than speed

  • #764263
    Hi all the below code is correct or not
    Dim returnValue As String = cmd.ExecuteScalar().ToString
    Dim recepient As String = lblCreatedBy.Text
    sendEmail(recepient, returnValue)
    Becuase when I add ddlcustodian.selectedvalue in recipient its sends to custodian not to createdby is their any error in the above code.

  • #764270
    Hai Nagendra,
    As you are not providing the From address, so the error message is displayed.
    If you are providing the from address using SMTP, then you need to retrieve it using Outlook API. Because I think while sending email, it will not pickup automatically the from email address.
    Below is the code snippet which can be helpful to you:

    https://msdn.microsoft.com/en-us/library/office/ff184624.aspx

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764274
    Hi pawan
    Dim recepient As String = ddlAlertOwner.SelectedValue & "," & lblCreatedBy.Text
    sendEmail(recepient, returnValue)
    when i change the receipent like above code the email sending to alert owner not to createdby i guess some issue in lblCreatedby.text

  • #764275
    Hi all I add FROM address but still shows the same error

  • #764282

    Hi Nagendra,

    Pass hard coded values in TO and FROM addresses just for debug purpose and try sending mail as like:

    mail.From = New MailAddress("xyz@gmail.com")
    mail.[To].Add("abc@gmail.com")

    from this you can trace whether the issue is in code or in email-id.

    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764283
    Hi Shashikant I did what u said received email


Sign In to post your comments