如何在隐藏窗口中发送电子邮件(隐形)

时间:2017-02-28 04:19:33

标签: vb.net email sendmail

- 抱歉编辑标题 -

我需要创建一个文件以隐藏模式发送电子邮件(隐藏窗口)

我有一个代码,可以在点击按钮时发送电子邮件 这是代码

Imports System.Net.Mail

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim Mail As New MailMessage
    Mail.Subject = "test email"
    Mail.To.Add("youremail@googlemail.com")
    Mail.From = New MailAddress("youremail@googlemail.com")
    Mail.Body = "This is an ownage email using VB.NET"

    Dim SMTP As New SmtpClient("smtp.gmail.com")
    SMTP.EnableSsl = True
    SMTP.Credentials = New System.Net.NetworkCredential("username", "password")
    SMTP.Port = "587"
    SMTP.Send(Mail)
End Sub

结束班

我想修改此代码,以便在运行文件时直接在隐藏窗口中发送电子邮件 请帮忙 并且抱歉更改标题

2 个答案:

答案 0 :(得分:1)

如果你想实际从gmail发送消息(而不是通过SMTP发送一条看起来像是从gmail发送的消息),你必须使用GMail API for .NET。你可以找到一些sample code that uses the Gmail API for .NET here,你可以找到information about using the API to send messages here

答案 1 :(得分:0)

这是一个从附带附件的VB发送邮件的代码段。

Public Sub SendMail(ByVal From As String, _
  ByVal sendTo As String, ByVal Subject As String, _
  ByVal Body As String, _
  Optional ByVal AttachmentFile As String = "", _
  Optional ByVal CC As String = "", _
  Optional ByVal BCC As String = "", _
  Optional ByVal SMTPServer As String = "")

    Dim myMessage As MailMessage

    Try
        myMessage = New MailMessage()
        With myMessage
            .To = sendTo
            .From = From
            .Subject = Subject
            .Body = Body
            .BodyFormat = MailFormat.Text
            'Custom mail message

            If CC <> "" Then .Cc = CC
            If BCC <> "" Then .Bcc = ""

            If FileExists(AttachmentFile) Then _
             .Attachments.Add(AttachmentFile)

        End With

        If SMTPServer <> "" Then _
           SmtpMail.SmtpServer = SMTPServer
        SmtpMail.Send(mailMessage)

    Catch ex As Exception
        Throw ex
    End Try

End Sub