使用vb.net从Windows应用程序发送电子邮件 [英] Send email from windows app using vb.net

查看:80
本文介绍了使用vb.net从Windows应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我正在尝试从我的Windows应用程序发送电子邮件,但它不起作用...任何帮助?请注意,我正在使用vb.net,我没有收到任何错误..我只是没有收到任何电子邮件!

i have the following code,i'm trying to send an email from my windows application but it's not working... any help ? note that i'm using vb.net and i'm not getting any errors.. i'm just not receiving any emails !

 Private Sub senemail()
    'create the mail message
    Dim mail As New MailMessage()

    'set the addresses
    mail.From = New MailAddress("jocelyne_elkhoury@inmobiles.net")
    mail.To.Add("jocelyne_el_khoury@hotmail.co.uk")

    'set the content
    mail.Subject = "This is an email"
    mail.Body = "this is a sample body"

    'send the message
    Dim smtp As New SmtpClient("127.0.0.1")
    smtp.Send(mail)
End Sub

推荐答案

您不太可能在此地址上启动并运行SMTP服务器,这是本地的。你需要使用一些外部服务器;并且您很可能需要在该服务器上注册并使用身份验证。



-SA
This is very unlikely that you have an SMTP server up and running on this address, which is local. You need to use some external server; and it also very likely that you will need to be registered with that server and use authentication.

—SA


Dim mail As New MailMessage()
        Dim SmtpServer As New SmtpClient("smtp.gmail.com")
        mail.From = New MailAddress(txtid.Text)
        mail.[To].Add("Email Id to send@rediffmail.com")
        mail.Subject = txtsub.Text
        mail.Body = txtmess.Text
        mail.Attachments.Add(New Attachment(OpenFileDialog1.FileName))
        SmtpServer.Port = 587
        SmtpServer.Credentials = New System.Net.NetworkCredential(txtid.Text, txtpass.Text)
        SmtpServer.EnableSsl = True
        SmtpServer.Send(mail)
        mail.From = New MailAddress(txtid.Text)
        MsgBox("E-mail Has Been Send Successfully !")



在vb.net中发送电子邮件非常简单,请查看此代码或直接使用。

如果你是发送附件,那么使用openfiledialogbox控件。


Its very simple to send email in vb.net please check this code or use directly.
If you are send attachment then use the openfiledialogbox control.


看看使用或不使用附件在C#中发送电子邮件:通用例程。 [ ^ ]



祝你好运

Espen Harlinn
Have a look at Sending an Email in C# with or without attachments: generic routine.[^]

Best regards
Espen Harlinn


这篇关于使用vb.net从Windows应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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