PDA

View Full Version : چگونه با .net ایمیل ارسال کنیم ؟



mgmehdiforme
چهارشنبه 25 آبان 1390, 18:21 عصر
چگونه با .net ایمیل ارسال کنیم ؟
من یک روش می دونم که کار نمی کنه

reza69
سه شنبه 09 اسفند 1390, 20:57 عصر
من یه کد دارم ولی کار نمی کنه برای ارسال به yahoo
Imports System.Net.Mail
Imports System.Net
Public Class Form1
Private Sub btnsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsend.Click
Try
Dim SendFrom As MailAddress = New MailAddress(txtto.Text)
Dim pass As String
pass = txtto.Text

Dim send As String
send = txtfrom.Text

Dim SendTo As MailAddress = New MailAddress(txtto.Text)
Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)

MyMessage.Subject = txtsubject.Text
MyMessage.Body = txtcoment.Text

If txtattach.Text.Length > 0 Then
Dim attachFile As New Attachment(txtattach.Text)
MyMessage.Attachments.Add(attachFile)
End If

Dim smtp As New SmtpClient
smtp.EnableSsl = False
smtp.Host = "smtp.mail.yahoo.com"
smtp.Port = 25
smtp.Credentials = New Net.NetworkCredential(send, pass)
smtp.Send(MyMessage)
MsgBox("ایمیل با موفقیت ارسال شد")
Finally
End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofdObj As New OpenFileDialog
ofdObj.Filter = "All Files|*.*"
If ofdObj.ShowDialog = vbOK Then
txtattach.Text = ofdObj.FileName
End If
End Sub
End Class

مرتضی تقدمی
سه شنبه 09 اسفند 1390, 21:29 عصر
سلام

http://barnamenevis.org/showthread.php?294074-%D8%A7%D8%B1%D8%B3%D8%A7%D9%84-%D8%A7%DB%8C%D9%85%DB%8C%D9%84&highlight=%D8%A7%DB%8C%D9%85%DB%8C%D9%84
تاپیک های دیگه ای هم مثل این در مورد ارسال ایمیل هست.

موفق باشید

reza69
سه شنبه 09 اسفند 1390, 21:59 عصر
ممنون درست شد ولی پیام ارسالی نا مفهومه

Imports EASendMail 'Add EASendMail namespace

Module Module1
Sub Main()
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New SmtpClient()

' Your Yahoo email address
oMail.From = "r_nba2008@yahoo.com"

' Set recipient email address, please change it to yours
oMail.To = "program1369@yahoo.com"

' Set email subject
oMail.Subject = "test email from yahoo account"

' Set email body
oMail.TextBody = "this is a test email sent from VB.NET project with yahoo"

' Yahoo SMTP server address
Dim oServer As New SmtpServer("smtp.mail.yahoo.com")

' For example: your email is "myid@yahoo.com", then the user should be "myid@yahoo.com"
oServer.User = "r_nba2008@yahoo.com"
oServer.Password = "my password email"

' Because yahoo deploys SMTP server on 465 port with direct SSL connection.
' So we should change the port to 465.
oServer.Port = 465

' detect SSL/TLS type automatically
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
Try
Console.WriteLine("start to send email over SSL ...")
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("email was sent successfully!")

Catch ep As Exception
Console.WriteLine("failed to send email with the following error:")
Console.WriteLine(ep.Message)
End Try
End Sub
End Module