Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello Experts,

Merry Christmas everyone.
I have a web application, which I need to send an email using smtp.
VB
Protected Sub SendEmail()
        Try
            Dim Client As SmtpClient = New SmtpClient
            Client.EnableSsl = True
            Client.DeliveryMethod = SmtpDeliveryMethod.Network
            Client.UseDefaultCredentials = False
            Client.Host = ""
            Client.Port = "587"

            Dim fromadd As MailAddress = New MailAddress("Su@m.com", "Sushmitha", System.Text.Encoding.UTF8)
            Dim toadd As MailAddress = New MailAddress("Su@m.com", "Sushi", System.Text.Encoding.UTF8)
            Dim msg As MailMessage = New MailMessage(fromadd, toadd)
            msg.Body = "Your information has been submitted successfully! And Here is your Invoice Number: 123. Merry Christmas"
            msg.Subject = " Claim Forms"
            Client.Send(msg)
        Catch ex As Exception

        End Try



    End Sub



And my question is I get an Failure in sending Error. I don't see anything wrong with this code. Ok I wanted to know following things before I start questions
1) what should be Host? is it "m.com". my email is "Su@m.com"
2) Is there any settings I need to do with my IIS?
3) What should I do to check/get the IP address of "m.com"?
4) How to know if there is any Firewall stopping this.

Note: I am testing the application and so I added from and to address same. I have gone through many other websites and also googled it but came empty handed.
Please help me in sorting these things out quickly.
Posted

You are totally missing the host name running the SMTP server. It has nothing to do with the host name part of your e-mail address. Think by yourself: what are you addressing to when trying to send a mail? What do you do if you use some available mail client to send your messages? You need to have some SMTP server and know its host name.

—SA
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 24-Dec-14 11:05am    
+5 for your suitable answer. Yes, she's missing the hostname, not only the hostname infact I believe she is now missing the service she used to register herself. If she knew, she would've got some help from there.
Sergey Alexandrovich Kryukov 24-Dec-14 11:08am    
Thank you, Afzaal.
—SA
sudevsu 24-Dec-14 11:38am    
Thank you so much
Sergey Alexandrovich Kryukov 24-Dec-14 11:55am    
You are very welcome.
Good luck, call again.
—SA
sudevsu 24-Dec-14 12:00pm    
Sure I will... Learning one by one so I need you experts ;-) Merry Christmas and Happy New year
Although you're just a newbie to this job I would still try to make the concept clear to you, as much as I can instead of forwarding you to MSDN.

1. The SMTP server host is totally different, you just don't always use the ending characters of your email-address to make up the SMTP server's address. For example, my email addres is "justinXXXXX@gmail.com", now, "gmail.com" is not my SMTP server's domain name. Instead it is, "smtp.gmail.com". It depends on how your client allows you to use their servers to send emails to your clients.

I have tried to Google for m.com, and I've always recieved a negative response also that m.com doesn't exist. Where did you register yourself? I would like to recommend you to use the Gmail (Outlook, Yahoo etc) servers to send and recieve emails until you're learning because of their free email sending budgets for users.

2. No, IIS is already set to allow you to send the emails through a connected server using their configurations. Which are, your username, password and a few other connection settings such as Port etc. Which you won't have to pay any fortune to get started, but in real you would just add them up while building that code of yours.

3. You do not need the IP address of their website or SMTP server domain at all. You will just input the string of domain name, and the DNS server will do the thing for you.

4. It depends on Windows Firewall settings, but usually you won't get any trouble while sending emails through Firewall unless there is any illegal activity.

To get an example of the code to send an email using VB.NET, please read this document it will explain the core concepts and will provide a sample to send the emails.

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2[^]
 
Share this answer
 
Comments
sudevsu 24-Dec-14 11:06am    
1) Oh yeah I cannot give to email so I just typed m.com instead typing all the email address... ;-) My client has lot of security loop holes.
2) ISS has nothing to do with my SMTP? So if I don't have IIS installed on my machine and I work on this Code... Do you think this is still going to work? (with correct Host name and Port name?
3) Got It.
4) Is it because of firewall, that my email is sitting in Junk folder instead of Inbox?

Very well Explained. Thank you so much. Looking forward for the answers I need from this message
Afzaal Ahmad Zeeshan 24-Dec-14 11:13am    
1. Wrong, when you're going to ask for help, tell everything sincerely. We're not going to hack into your systems and we're also not very free all the time to keep sending you spammy emails. Yes, do not share your passwords, ever!

2. Yes, it will still work! Because the .NET application is going to make a direct request to your client (SMTP client, Gmail, Outlook etc) and they're going to get a request through Internet connection. IIS will be required, if your application is being hosted in IIS; such as Websites.

3. No, firewall would just block the traffic instead of sending the traffic with a flag of "Add to Junk folder". Firewall is just a mean to block the traffic at all.
sudevsu 24-Dec-14 11:37am    
Alright I totally agree with all the points.(Its little harsh to take the words of point 1) But I got the answers what I need and so that's negligible . Ok now, then why is my email sitting in Junk folder?
Sergey Alexandrovich Kryukov 24-Dec-14 11:08am    
5ed.
—SA
Afzaal Ahmad Zeeshan 24-Dec-14 11:10am    
Thanks Sergey. :-)
I solved this... Initially when I had this question what is SMTP host, I have no clue that you alone can look SMTP host from your command prompt. Finally got the solution ... now there is no error in sending email. And Here is the corrected code.

VB
Dim Client As SmtpClient = New SmtpClient
           Client.EnableSsl = False
           Client.DeliveryMethod = SmtpDeliveryMethod.Network
           Client.UseDefaultCredentials = False
           Client.Host = "m.org"
           Client.Port = "25"

           Dim fromadd As MailAddress = New MailAddress("S@m.com", "S", System.Text.Encoding.UTF8)
           Dim toadd As MailAddress = New MailAddress("S@m.com", "S", System.Text.Encoding.UTF8)
           Dim msg As MailMessage = New MailMessage(fromadd, toadd)
           msg.Body = "Your information has been submitted successfully! And Here is your Invoice Number: 123. Merry Christmas"
           msg.Subject = "Claim Forms"
           Client.Send(msg)


But the Email is sitting in Junk Folder. Is there any way that I can make the email sit directly on Inbox.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900