小编Mar*_*nic的帖子

在symfony中使用带有swiftmailer的office365服务器发送电子邮件

我正在尝试使用 symfony 中的 swiftmailer 和 office365 服务器在注册后发送确认电子邮件。我已经尝试了我遇到的所有主机、端口和加密类型的组合。

目前我的 .env 文件包含这一行:

MAILER_URL=smtp://smtp.office365.com:587?encryption=ssl&auth_mode=login&username="myusername@mycompany.com"&password="mypassword"
Run Code Online (Sandbox Code Playgroud)

*注意:我使用“”作为我的用户名和密码,因为它们包含特殊字符,我在某处读到这可能会导致 MAILER_URL 出现问题。

我的 swiftmailer.yaml 文件包含以下内容:

swiftmailer:
    url: '%env(MAILER_URL)%'
    stream-options:
        ssl:
            allow_self_signed : true
            verify_peer: false
Run Code Online (Sandbox Code Playgroud)

最后,我在控制器中使用此代码发送电子邮件:

 $message = (new \Swift_Message('Referral tool registration'))
            ->setFrom('myusername@mycompany.com')
            ->setTo('test@gmail.com')
            ->setBody(
                $this->renderView(
                    'email/notification/user_registered.html.twig',
                    ['firstName' => $user->getFirstName(),
                     'lastName' => $user->getLastName()
                    ]
                    ),
                'text/html'
            );

 $mailer->send($message);
Run Code Online (Sandbox Code Playgroud)

通过当前选择的主机、端口和加密,我得到: "Connection could not be established with host smtp.office365.com [ #0]"

更新:当我输入 telnet smtp.office365.com 587 时,我得到了一个有效的响应,所以我认为问题与网络无关,端口没有被阻止。

php swiftmailer symfony office365 symfony4

4
推荐指数
1
解决办法
4573
查看次数

使用 HttpClient 将 Zip 文件上传到 ASP.NET Core WebAPI 服务,但 IFormData 参数始终为空

正如标题所说,我正在尝试将 .zip 从我的 WPF 应用程序上传到我的 .NET Core Web API。

经过一些研究,我发现可以使用 MultiPartDataContent 并以这种方式发送它。

将数据发送到服务器的代码如下所示:

            {
                client.BaseAddress = new Uri("http://localhost:62337/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                string filepath = @"C:\Users\uic10950\Desktop\Meeting2Text\RecordingApp\bin\mixedaudio.zip";
                string filename = "mixedaudio.zip";

                MultipartFormDataContent content = new MultipartFormDataContent();
                ByteArrayContent fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filepath));

                fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = filename };
                content.Add(fileContent);

                HttpResponseMessage response = await client.PostAsync("api/transcriptions/recording", content);
                string returnString = await response.Content.ReadAsAsync<string>();
            }
Run Code Online (Sandbox Code Playgroud)

在服务器端,我的控制器操作如下所示:

        public async Task<IActionResult> AddFileToTranscription([FromForm] IFormFile file)
        {
            using (var sr = new StreamReader(file.OpenReadStream()))
            {
                var content = await …
Run Code Online (Sandbox Code Playgroud)

c# wpf dotnet-httpclient asp.net-core-webapi

0
推荐指数
1
解决办法
2417
查看次数