Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello!
Iam quite new here, and I have a problem.
Iam a begginer in C#. I want to write a console app, which can send email.
I have a VB source code, and I cant translate it to C#, so:
-Does anyone know how to translate/convert this VB source code to C#?
Thank you very much!

Imports System.Net.Mail
Module Module1
    Public Region As String
    Public Key As String
    Sub Main()
        Console.WriteLine("Hello! Ird be az országot és a kodot!")
        Region = Console.ReadLine
        Key = Console.ReadLine
        Sendmail()
    End Sub
    Sub Sendmail()
        Dim WC As New System.Net.WebClient
        Dim MyMailMessage As New MailMessage
        MyMailMessage.From = New MailAddress("ferike112@gmail.com")
        MyMailMessage.To.Add("ferike112@gmail.com")
        MyMailMessage.Subject = ("Region:" & Region & "Their IP is: " & System.Text.Encoding.ASCII.GetString((WC.DownloadData("http://whatismyip.com/automation/n09230945.asp"))))
        WC.Dispose()
        MyMailMessage.Body = ("REGION: " & Region & vbCrLf & "Key: " & Key)
        Dim SMTPServer As New SmtpClient("smtp.gmail.com")
        SMTPServer.Port = 587
        SMTPServer.Credentials = New System.Net.NetworkCredential("ferike112@gmail.com", "********")
        SMTPServer.EnableSsl = True
        Try
            SMTPServer.Send(MyMailMessage)

        Catch ex As SmtpException
            'MessageBox.Show(ex.Message)
        End Try
    End Sub
End Module
Posted

There are VB to C# converters, C# samples for sending mail, etc, all over the web. Also, blindly using code off the web is not a way to learn, buy a book and read it, if you're not able to convert this VB to C# then you don't know enough C# to really understand the code.
 
Share this answer
 
Thank you guys! You helped me alot! :D
 
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