通过gmail使用asp.net发送电子邮件 [英] Send email using asp.net through gmail
本文介绍了通过gmail使用asp.net发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我是否知道如何使用visual studio 2010以电子邮件形式发送电子邮件?
它与SMTP有关。
我可以知道在哪里可以获得相关的教程或学习步骤吗?我是编码的新手。
谢谢
Hi. May I know how to send an email as text using visual studio 2010?
It is related to SMTP something.
Can I know where can i get related tutorials or steps to learn? I am new to codings.
Thank You
推荐答案
protected void Button1_Click(object sender, EventArgs e)
{
//string path = "D:\\Test.txt";
try
{
MailMessage mail = new MailMessage();
mail.To.Add("imran3may@gmail.com");
mail.To.Add("shi01715@yahoo.com");
mail.From = new MailAddress("shishir64092@gmail.com");
mail.Subject = "Send Email by asp.net code using google or gmail smtp server";
string Body = "Hi, I am testing Email function in asp.net" +
" using google or gmail smtp server"+
" and next time I will send you a document from my .aspx file";
mail.Body = Body;
Attachment at = new Attachment("D:\\Text.txt");
mail.Attachments.Add(at);
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("localhost",25);
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("shishir64092@gmail.com", "abcdef");
//Or your Smtp Email ID and Password
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Send(mail);
Label1.Text = "Mail Send...";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
in mail.To.Add
您设置邮件目标地址,并在凭据
中使用密码设置邮件发件人地址!
in mail.To.Add
you set the mail target address, and in Credentials
you set the mail sender address with password!
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add("luckyperson@online.microsoft.com");
message.Subject = "This is the Subject line";
message.From = new System.Net.Mail.MailAddress("From@online.microsoft.com");
message.Body = "This is the message body";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("yoursmtphost");
smtp.Send(message);
Imports System.Net.Mail
Partial Class Newsletter_admin
Inherits System.Web.UI.Page
Private Function MessageBox() As Object
Throw New NotImplementedException
End Function
Protected Sub Reset_Click(sender As Object, e As System.EventArgs) Handles Reset.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Protected Sub SendMail_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SendMail.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("fionatan06@gmail.com", "password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
mail = New MailMessage()
mail.From = New MailAddress("fionatan06@gmail.com")
mail.To.Add(TextBox2.Text)
mail.Subject = TextBox3.Text
mail.IsBodyHtml = True
mail.Body = TextBox4.Text + "<br></br><br></br>This is an auto-generated message. Please do not reply. Thank you.<br></br><br></br>Colore"
Dim MyAttachment As Attachment = New Attachment("C:\Users\Admin\Desktop\EAIPJ(Coloré-Rachel,Peiwen,Sherry,Fiona)\Coloré\Images\BLACK SHATTER.jpg")
mail.Attachments.Add(MyAttachment)
SmtpServer.Send(mail)
MsgBox("Mail Send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
这篇关于通过gmail使用asp.net发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文